問(wèn)題描述
找到核心錯(cuò)誤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
翻譯:
錯(cuò)誤:需要 Microsoft Visual C++ 14.0 或更高版本。使用“Microsoft C++ 構(gòu)建工具”獲取它:https://visualstudio.microsoft.com/visual-cpp-build-tools/
錯(cuò)誤:wordcloud 構(gòu)建輪子失敗
分析:1.缺少M(fèi)icrosoft C++組件,需要安裝
首先這是一個(gè)辦法,但是下載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
問(wèn)題解決
這里我們采用的是下載whl文件的方法(文件比較小)
1.咱們先查看python版本,如果你是anaconda也可以的
命令:python --version
2.打開(kāi)網(wǎng)址,下載對(duì)應(yīng)的whl文件,我這里是64位3.9的版本
https://www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud
3.安裝whl文件
將下載好的whl放入Libray文件架(養(yǎng)成習(xí)慣,方便管理)
導(dǎo)航刀whl所在的目錄
執(zhí)行命令:pip install wordcloud-1.8.1-cp39-cp39-win_amd64.whl
提示:這里的命令手動(dòng)輸?shù)脑捜菀壮鲥e(cuò),可以重命名復(fù)制whl的名字就行,反正我是這么干的哈哈哈
4.接著執(zhí)行:pip install wordcloud
因?yàn)槲疫@里已經(jīng)安裝了所以是already satisfied
下面是打包好的案例,你只需要把圖片路徑替換成你的就行文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-461093.html
import wordcloud #導(dǎo)入詞云庫(kù)
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()
#導(dǎo)入圖片
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') #設(shè)置詞云圖對(duì)象屬性
st1 = re.sub('[,。、“”‘ ’]','',str(text1)) #使用正則表達(dá)式將符號(hào)替換掉。
conten = ' '.join(jieba.lcut(st1)) #此處分詞之間要有空格隔開(kāi),聯(lián)想到英文書寫方式,每個(gè)單詞之間都有一個(gè)空格。
con = WC.generate(conten)
plt.imshow(con)
plt.axis("off")
plt.savefig('111.png')
plt.show()
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-461093.html
到了這里,關(guān)于Python 安裝wordcloud報(bào)錯(cuò)error: Microsoft Visual C++ 14.0 or greater is required.的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!