简体   繁体   English

python如何安装wordcloud?

[英]How to install wordcloud for python?

I am trying to visualise data using word cloud.我正在尝试使用词云来可视化数据。 However when I used pip install wordcloud , I got the following error:但是,当我使用pip install wordcloud时,出现以下错误:

D:\...>pip install wordcloud
Collecting wordcloud
  Using cached wordcloud-1.8.1.tar.gz (220 kB)
Requirement already satisfied: numpy>=1.6.1 in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from wordcloud) (1.19.5
)
Requirement already satisfied: pillow in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from wordcloud) (8.1.0)
Requirement already satisfied: matplotlib in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from wordcloud) (3.3.3)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from matplotlib
->wordcloud) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from matplotlib->w
ordcloud) (1.3.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packa
ges (from matplotlib->wordcloud) (2.4.7)
Requirement already satisfied: cycler>=0.10 in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from matplotlib->wordcl
oud) (0.10.0)
Requirement already satisfied: six in c:\users\ameli\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from cycler>=0.10->matplotlib->w
ordcloud) (1.15.0)
Using legacy 'setup.py install' for wordcloud, since package 'wheel' is not installed.
Installing collected packages: wordcloud
    Running setup.py install for wordcloud ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\ameli\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ameli\\Ap
pData\\Local\\Temp\\pip-install-i40_agzl\\wordcloud_591db346adc745a0a41bcad116c4a453\\setup.py'"'"'; __file__='"'"'C:\\Users\\ameli\\AppData\\Local\\Temp\\pip-install-i40_agzl\\wordcloud_591db346adc745a0a41bc
ad116c4a453\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:
\Users\ameli\AppData\Local\Temp\pip-record-odcy4xrk\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\ameli\AppData\Local\Packages\PythonSoftwareFo
undation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Include\wordcloud'
         cwd: C:\Users\ameli\AppData\Local\Temp\pip-install-i40_agzl\wordcloud_591db346adc745a0a41bcad116c4a453\
    Complete output (20 lines):
    running install
    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 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\ameli\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import sys, setuptools, tokenize; sys.ar
gv[0] = '"'"'C:\\Users\\ameli\\AppData\\Local\\Temp\\pip-install-i40_agzl\\wordcloud_591db346adc745a0a41bcad116c4a453\\setup.py'"'"'; __file__='"'"'C:\\Users\\ameli\\AppData\\Local\\Temp\\pip-install-i40_agzl
\\wordcloud_591db346adc745a0a41bcad116c4a453\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'
exec'"'"'))' install --record 'C:\Users\ameli\AppData\Local\Temp\pip-record-odcy4xrk\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\ameli\AppDat
a\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Include\wordcloud' Check the logs for full command output.

Wordcloud is not a pure Python project as it has some C code. Wordcloud 不是一个纯粹的 Python 项目,因为它有一些 C 代码。 C code needs to be built for different operating systems and Python versions. C代码需要针对不同的操作系统和Python版本构建。 Normally when you run pip install wordcloud , pip tries to find a built package (aka wheel) for your OS and Python but if it can't find, it downloads the source code and tries to build (compile) it.通常,当您运行pip install wordcloud时,pip 会尝试为您的操作系统找到内置的 package(又名轮子)和 Python,但如果找不到,它会下载源代码并尝试构建(编译)它。 But this process obviously requires a C compiler which is not supposed to be in a Python developer's system.但是这个过程显然需要一个 C 编译器,它不应该在 Python 开发人员的系统中。

I built the package for several configurations and made them public .我为几种配置构建了 package 并将它们公开 You can directly install from there.您可以直接从那里安装。 For example if you use Windows and Python 3.10, run pip install https://github.com/sulunemre/word_cloud/releases/download/2/wordcloud-0.post1+gd8241b5-cp310-cp310-win_amd64.whl例如,如果您使用 Windows 和 Python 3.10,请运行pip install https://github.com/sulunemre/word_cloud/releases/download/2/wordcloud-0.post1+gd8241b5-cp310-cp310-win_amd64.whl

As mentioned in comments, downloading the build tools from this link and running the .exe file solved the problem.如评论中所述,从此链接下载构建工具并运行.exe文件解决了该问题。

Installing wordcloud for python为 python 安装 wordcloud

Wordcloud installation throws error if not satified any of these steps:如果不满足以下任何步骤,Wordcloud 安装会引发错误:

  1. Installing the dependencies of wordcloud: matplotlib, pillow, numpy, pandas安装wordcloud的依赖:matplotlib、pillow、numpy、pandas
  2. Checking for version of Python used检查使用的 Python 的版本
  3. Checking for version of operating system检查操作系统的版本
  4. Checking for version of wordcloud satisfying the version of Python and operating system used检查 wordcloud 的版本是否满足 Python 的版本和使用的操作系统

Missing to check version of wordcloud satisfying the version of python and operating system used doesn't help building wheel for installing wordcloud.缺少检查满足 python 版本的 wordcloud 版本和使用的操作系统无助于构建安装 wordcloud 的轮子。

Current latest version of wordcloud is 1.8.1 Installing wordcloud:当前最新的 wordcloud 版本是 1.8.1 安装 wordcloud:

pip install wordcloud==1.8.1

The code is tested against Python 2.7, 3.4, 3.5, 3.6 and 3.7.该代码针对 Python 2.7、3.4、3.5、3.6 和 3.7 进行了测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM