问题描述
找到核心错误error:
1. error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
2. ERROR: Failed building wheel for wordcloud
翻译: 错误:需要 Microsoft Visual C++ 14.0 或更高版本。使用“Microsoft C++ 构建工具”获取它:https://visualstudio.microsoft.com/visual-cpp-build-tools/ 错误:wordcloud 构建轮子失败 分析:1.缺少Microsoft C++组件,需要安装 首先这是一个办法,但是下载Visual太大(100M) 2.建议下载wheel文件
Building wheels for collected packages: wordcloud
Building wheel for wordcloud (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'D:\Users\20735\anaconda3\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\20735\\AppData\\Local\\Temp\\pip-install-ei543uiq\\wordcloud_976575344b2540e495e42e0a0576368d\\setup.py'"'"'; __file__='"'"'C:\\Users\\20735\\AppData\\Local\\Temp\\pip-install-ei543uiq\\wordcloud_976575344b2540e495e42e0a0576368d\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\20735\AppData\Local\Temp\pip-wheel-zfgap6p_'
cwd: C:\Users\20735\AppData\Local\Temp\pip-install-ei543uiq\wordcloud_976575344b2540e495e42e0a0576368d\
Complete output (20 lines):
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.9
creating build\lib.win-amd64-3.9\wordcloud
copying wordcloud\color_from_image.py -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\tokenization.py -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\wordcloud.py -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\wordcloud_cli.py -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\_version.py -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\__init__.py -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\__main__.py -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\stopwords -> build\lib.win-amd64-3.9\wordcloud
copying wordcloud\DroidSansMono.ttf -> build\lib.win-amd64-3.9\wordcloud
UPDATING build\lib.win-amd64-3.9\wordcloud/_version.py
set build\lib.win-amd64-3.9\wordcloud/_version.py to '1.8.1'
running build_ext
building 'wordcloud.query_integral_image' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
----------------------------------------
ERROR: Failed building wheel for wordcloud
问题解决
这里我们采用的是下载whl文件的方法(文件比较小) 1.咱们先查看python版本,如果你是anaconda也可以的 命令:python --version 2.打开网址,下载对应的whl文件,我这里是64位3.9的版本 https://www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud
3.安装whl文件 将下载好的whl放入Libray文件架(养成习惯,方便管理) 导航刀whl所在的目录 执行命令:pip install wordcloud-1.8.1-cp39-cp39-win_amd64.whl 提示:这里的命令手动输的话容易出错,可以重命名复制whl的名字就行,反正我是这么干的哈哈哈
4.接着执行:pip install wordcloud 因为我这里已经安装了所以是already satisfied
下面是打包好的案例,你只需要把图片路径替换成你的就行
import wordcloud #导入词云库
import numpy as np
import matplotlib.pyplot as plt
import PIL
import jieba
import re
with open(r'Q10_20220412.csv',encoding='utf8') as f:
text1 = f.readlines()
#导入图片
image1 = PIL.Image.open(r'owl.jpeg ')
MASK = np.array(image1)
WC = wordcloud.WordCloud(font_path = 'C:\\Windows\\Fonts\\STFANGSO.TTF',max_words=2000,mask = MASK,height= 400,width=400,background_color='white',repeat=False,mode='RGBA') #设置词云图对象属性
st1 = re.sub('[,。、“”‘ ’]','',str(text1)) #使用正则表达式将符号替换掉。
conten = ' '.join(jieba.lcut(st1)) #此处分词之间要有空格隔开,联想到英文书写方式,每个单词之间都有一个空格。
con = WC.generate(conten)
plt.imshow(con)
plt.axis("off")
plt.savefig('111.png')
plt.show()
|