当前位置:   article > 正文

Python 安装wordcloud报错error: Microsoft Visual C++ 14.0 or greater is required._failed building wheel for wordcloud

failed building wheel for wordcloud

问题描述

找到核心错误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
  • 1
  • 2
  • 3

翻译:
错误:需要 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

问题解决

这里我们采用的是下载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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/137640
推荐阅读
相关标签
  

闽ICP备14008679号