简体   繁体   English

导入错误:无法导入名称'_path' matplotlib

[英]ImportError: cannot import name '_path' matplotlib

When importing matplotlib by import matplotlib.pyplot as plt I'm getting the following error:通过import matplotlib.pyplot as plt时出现以下错误:

Traceback (most recent call last):   File "mode.py", line 1, in <module>
    import matplotlib.pyplot as plt   File "C:\Users\yuhan\AppData\Roaming\Python\Python36\site-packages\matplotlib\pyplot.py", line 32, in <module>
    import matplotlib.colorbar   File "C:\Users\yuhan\AppData\Roaming\Python\Python36\site-packages\matplotlib\colorbar.py", line 32, in <module>
    import matplotlib.artist as martist   File "C:\Users\yuhan\AppData\Roaming\Python\Python36\site-packages\matplotlib\artist.py", line 16, in <module>
    from .path import Path   File "C:\Users\yuhan\AppData\Roaming\Python\Python36\site-packages\matplotlib\path.py", line 25, in <module>
    from . import _path, rcParams ImportError: cannot import name '_path'

I tried reinstalling the whole matplotlib library, tried re-installing Python 3.6 etc. I really do not know what is wrong and since I don't have a backup.我尝试重新安装整个 matplotlib 库,尝试重新安装 Python 3.6 等。我真的不知道出了什么问题,因为我没有备份。

py -m pip uninstall matplotlib

then:然后:

py -m pip install matplotlib

worked for me for that error as well.也为我工作了那个错误。

Then I had a problem of kiwisolver not being found, and did the same uninstall, install for kiwisolver and now: import matplotlib.pyplot as plt works.然后我遇到了找不到 kiwisolver 的问题,并做了同样的卸载,为 kiwisolver 安装,现在: import matplotlib.pyplot as plt works。

This problem can pop up when you copy libraries from place to place (at least that's what happend with me:P)当你从一个地方复制库到另一个地方时,这个问题会弹出(至少我是这样的:P)

Make sure that in .../Python37/Lib/site-packages there is a file named: matplotlib-3.0.2-py3.7-nspkg.pth with the correct version of Python and matplotlib确保在.../Python37/Lib/site-packages中有一个名为: matplotlib-3.0.2-py3.7-nspkg.pth 的文件,其中包含正确版本的 Python 和 matplotlib

(in this example I am using python 3.7.1 and matplotlib 3.0.2) (在这个例子中我使用的是 python 3.7.1 和 matplotlib 3.0.2)

If that's not the case, reinstall matplotlib like other users suggested.如果不是这种情况,请像其他用户建议的那样重新安装 matplotlib。 Make sure also that you are targeting the correct directory (sometimes I've seen that the problem might be the wrong version of pip)还要确保你的目标目录是正确的(有时我发现问题可能出在错误的 pip 版本上)

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

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