【问题标题】:An ImportError occurs when importing matplotlib导入 matplotlib 时出现 ImportError
【发布时间】:2021-05-22 03:15:49
【问题描述】:

我通过下载https://www.lfd.uci.edu/~gohlke/pythonlibs/中的轮子在pypy中安装matplotlib,它的名称是matplotlib‑3.4.2‑pp37‑pypy37_pp73‑win_amd64.whl

我的pypy版本是
Python 3.7.10 (51efa818fd9b, Apr 04 2021, 12:09:32) [PyPy 7.3.4 with MSC v.1927 64 bit (AMD64)]在win32上。

但是当我导入 matplolib 时发生了错误。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Bitao_Dai\pypy3.7-v7.3.4-win64\site-packages\matplotlib\__init__.py", line 107, in <module>
    from . import _api, cbook, docstring, rcsetup
  File "C:\Users\Bitao_Dai\pypy3.7-v7.3.4-win64\site-packages\matplotlib\cbook\__init__.py", line 31, in <module>
    from matplotlib import _api, _c_internal_utils
ImportError: cannot import name '_c_internal_utils'

【问题讨论】:

    标签: python matplotlib importerror pypy


    【解决方案1】:

    似乎在安装过程中出现了问题,文件未安装或已损坏,有时我也遇到了同样的错误。 以下解决方案对我有用: 转到 cmd.exe,处理你的 venv(如果你正在使用一个),否则输入:

    (venv) C:>pip uninstall matplotlib
    Found existing installation: matplotlib 3.4.2
    Uninstalling matplotlib-3.4.2:
     Would remove:
      c:\matplotlib-3.4.2-py3.9-nspkg.pth
      c:\matplotlib-3.4.2.dist-info\*
      c:\site-packages\matplotlib\*
      c:\mpl_toolkits\axes_grid1\*
      c:\mpl_toolkits\axes_grid\*
      c:\mpl_toolkits\axisartist\*
      c:\mpl_toolkits\mplot3d\*
      c:\mpl_toolkits\tests\*
      c:\pylab.py
    Proceed (y/n)? y
     Successfully uninstalled matplotlib-3.4.2
    

    之后: (venv) C:>pip install matplotlib

    这应该可行。希望这有帮助。根据我的经验,使用 pip 安装软件包是最佳做法。

    当我运行 pypy3 -m pip install matplotlib 时,发生了一些麻烦

    错误:命令出错,退出状态为 1: 命令:'C:\Users\Bitao_Dai\pypy3.7-v7.3.4-win64\pypy3.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\BITAO_~1\AppData\Local\Temp\pip-install-xzb8mrhq\matplotlib_c20db475c8ba4ee6bec5b5683911048a\setup.py'"'"'; 文件='"'"'C:\Users\BITAO_~1\AppData\Local\Temp\pip-install-xzb8mrhq\matplotlib_c20db475c8ba4ee6bec5b5683911048a\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'"'"'))' install --record 'C:\Users \BITAO_~1\AppData\Local\Temp\pip-record-narl5jt6\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Bitao_Dai\pypy3. 7-v7.3.4-win64\include\matplotlib' cwd: C:\Users\BITAO_~1\AppData\Local\Temp\pip-install-xzb8mrhq\matplotlib_c20db475c8ba4ee6bec5b5683911048a
    完整输出(552 行):

    Edit setup.cfg to change the build options; suppress output with --quiet.
    

    错误:需要 Microsoft Visual C++ 14.0。使用“Visual Studio 构建工具”获取它:https://visualstudio.microsoft.com/downloads/ -------------------------------------- 错误:命令出错,退出状态为 1:'C:\Users\Bitao_Dai\pypy3.7-v7.3.4-win64\pypy3.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\BITAO_~1\AppData\Local\Temp\pip-install-xzb8mrhq\matplotlib_c20db475c8ba4ee6bec5b5683911048a\setup.py'"'"'; 文件='"'"'C:\Users\BITAO_~1\AppData\Local\Temp\pip-install-xzb8mrhq\matplotlib_c20db475c8ba4ee6bec5b5683911048a\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'"'"'))' install --record 'C:\Users \BITAO_~1\AppData\Local\Temp\pip-record-narl5jt6\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Bitao_Dai\pypy3. 7-v7.3.4-win64\include\matplotlib' 检查日志以获取完整的命令输出。

    【讨论】:

    • 谢谢。我试过你的评论。其实我用的是pypy,一个特殊的python。当我运行 pypy3 -m pip install matplotlib 时,发生了一些麻烦
    • 好的,看起来 pypy 不支持 matplotlib,请参阅 link 了解支持的软件包。我能找到的只是 2.2 版可以工作,你试过了吗: pypy3 -m pip install matplotlib 或 pypy3 -m pip install matplotlib==2.2
    • 这个页面已经过时了。
    猜你喜欢
    • 1970-01-01
    • 2014-08-01
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多