浅记已经导入wordcloud还显示ModuleNotFoundError: No module named ‘wordcloud‘的问题

需词云图,import wordcloud报错:

Traceback (most recent call last):
  File "D:\PyCharm\PycharmProjects\pythonProject\demo03.py", line 10, in <module>
    import WordCloud
ModuleNotFoundError: No module named 'WordCloud'

查找资料,找到靠谱资料。
解决方法1:
参考链接:安装路径错误时可点击此
检查python安装路径

# 显示python的默认安装路径
import sys
print(sys.executable)

在系统中输入cmd命令,将wordcloud安装在python的路径下

c:\users\wm\appdata\local\programs\python\python36\python -m pip install wordcloud

注意写自己的路径,不是直接复制这里的。
文章作者这样解决了问题,而我没有,继续报了错:
浅记已经导入wordcloud还显示ModuleNotFoundError: No module named ‘wordcloud‘的问题_第1张图片
根据提示,运行下列语句更新pip

 D:\PyCharm\PycharmProjects\pythonProject\venv\Scripts\python.exe -m pip install --upgrade pip

successfully了,略显欣慰
继续

PS D:\PyCharm\PycharmProjects\pythonProject> D:\PyCharm\PycharmProjects\pythonProject\venv\Scripts\python.exe -m pip install wordcloud 
Collecting wordcloud
  Using cached wordcloud-1.8.1.tar.gz (220 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy>=1.6.1 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from wordcloud) (1.22.3)
Requirement already satisfied: pillow in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from wordcloud) (9.1.1)
Requirement already satisfied: matplotlib in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from wordcloud) (3.5.2)
Requirement already satisfied: pyparsing>=2.2.1 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from matplotlib->wordcloud) (3.0.9) 
Requirement already satisfied: kiwisolver>=1.0.1 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from matplotlib->wordcloud) (1.4.2)
Requirement already satisfied: packaging>=20.0 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from matplotlib->wordcloud) (21.3)   
Requirement already satisfied: cycler>=0.10 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from matplotlib->wordcloud) (0.11.0)    
Requirement already satisfied: fonttools>=4.22.0 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from matplotlib->wordcloud) (4.33.3)
Requirement already satisfied: python-dateutil>=2.7 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from matplotlib->wordcloud) (2.8.2)
Requirement already satisfied: six>=1.5 in d:\pycharm\pycharmprojects\pythonproject\venv\lib\site-packages (from python-dateutil>=2.7->matplotlib->wordcloud) (1.16.0)
Building wheels for collected packages: wordcloud
  Building wheel for wordcloud (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [66 lines of output]
      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
      Traceback (most recent call last):
        File "", line 2, in <module>
        File "", line 34, in <module>
        File "C:\Users\lenovo\AppData\Local\Temp\pip-install-t57ystk_\wordcloud_7697356f0cd340b19c3412d0691b3df3\setup.py", line 9, in <module>
          setup(
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\__init__.py", line 155, in setup
          return distutils.core.setup(**attrs)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\core.py", line 148, in setup
          return run_commands(dist)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\core.py", line 163, in run_commands
          dist.run_commands()
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\dist.py", line 967, in run_commands
          self.run_command(cmd)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
          cmd_obj.run()
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\wheel\bdist_wheel.py", line 299, in run
          self.run_command('build')
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
          cmd_obj.run()
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\command\build.py", line 135, in run
          self.run_command(cmd_name)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
          cmd_obj.run()
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\command\build_ext.py", line 79, in run
          _build_ext.run(self)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 339, in run
          self.build_extensions()
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 448, in build_extensions
          self._build_extensions_serial()
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 473, in _build_extensions_serial
          self.build_extension(ext)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\command\build_ext.py", line 202, in build_extension
          _build_ext.build_extension(self, ext)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 528, in build_extension 
          objects = self.compiler.compile(sources,
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 327, in compile
          self.initialize()
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 224, in initialize
          vc_env = _get_vc_env(plat_spec)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\msvc.py", line 316, in msvc14_get_vc_env
          return _msvc14_get_vc_env(plat_spec)
        File "D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\msvc.py", line 270, in _msvc14_get_vc_env
          raise distutils.errors.DistutilsPlatformError(
      setuptools._distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for wordcloud
  Running setup.py clean for wordcloud
Failed to build wordcloud
Installing collected packages: wordcloud
  Running setup.py install for wordcloud ... error
  error: subprocess-exited-with-error

  × Running setup.py install for wordcloud did not run successfully.
  │ exit code: 1
  ╰─> [21 lines of output]
      running install
      D:\PyCharm\PycharmProjects\pythonProject\venv\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      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
      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/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> wordcloud

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

很好,一大片看起来很高级的报错
尝试在setting里面安装
浅记已经导入wordcloud还显示ModuleNotFoundError: No module named ‘wordcloud‘的问题_第2张图片
不可

解决方法2:
新的报错:参考2

ERROR: wordcloud-1.8.1-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.

果断查阅资料,很好,看到一个靠谱的回答
靠谱解决方法3
但是我的还是不行

很好,本篇文章可以凑齐此类问题的所有解决方案了
很好,看到一个靠谱的回答,要上课迟到了,回来再试
靠谱未试
上课去晚了,被记了迟到,不错。
试一试上面的靠谱,
很好,新的报错产生了

  • 新的办法一:打开cmd,进入下载wordcloud的文件夹
    注意在C盘下时,首先输入D:进入D盘,再用cd D:\xxx\xxx 这里是写下载的wordcloud的文件夹,进入后pip install wordcloud-1.8.1-xxxxxxxx 写自己的文件名。

浅记已经导入wordcloud还显示ModuleNotFoundError: No module named ‘wordcloud‘的问题_第3张图片
上面的方法我也用了,没有成功。
最终成功的解决方法:
浅记已经导入wordcloud还显示ModuleNotFoundError: No module named ‘wordcloud‘的问题_第4张图片
嗯,终于没有红杠杠了。
感谢这位友友!
浅记已经导入wordcloud还显示ModuleNotFoundError: No module named ‘wordcloud‘的问题_第5张图片

你可能感兴趣的:(python,pycharm,开发语言)