简体   繁体   English

matplotlib.pyplot错误“导入错误:无法导入名称'_path'”

[英]matplotlib.pyplot Error “ImportError: cannot import name '_path'”

I came across an ImportError in the importing of matplotlib.pyplot on Windows 10 Pro 我在Windows 10 Pro上导入matplotlib.pyplot时遇到了ImportError

Here is the full error: 这是完整的错误:

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

Here is the script: 这是脚本:

import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()

If anyone could help me, much appreciated. 如果有人可以帮助我,万分感谢。

Dunno什么是mpip,或者为什么,尝试使用普通的旧pip(或者在您的情况下,可能是pip3?这可能与基本Python的安装方式有更多关系,为什么我建议使用Anaconda安装所有(自动安装) MPL也是..)

It can be a problem related to matplotlib version. 这可能是与matplotlib版本有关的问题。 I had the same problem and solved it uninstalling the existing version of matplotlib (in my case with conda but the command is similar substituing pip to conda ) so: firstly uninstalling with: 我遇到了同样的问题,并解决了该问题,并卸载了现有版本的matplotlib(在我的情况下为conda,但命令类似于将pip替换为conda ),因此:首先使用以下命令进行卸载:

conda uninstall matplotlib (or pip uninstall matplotlib)

and after the successful removal of the existing version (mine was 2.2.2), the following command installed a successive version, that can be specified with '==' after the module name: 在成功删除现有版本(我的版本是2.2.2)之后,以下命令安装了一个后续版本,可以使用模块名称后的'=='进行指定:

 conda install matplotlib==3.0.2 (or pip install matplotlib==3.0.2)

and the error disappears. 错误消失了。 The uninstall command removed also seaborn installation so it was necessary to install it after matplotlib but it was easy... Yeah!:) 卸载命令也删除了seaborn安装,因此有必要在matplotlib之后安装它,但这很容易...是的!:)

Since you're probably like me and doing a lot of installing/importing , it can be just a mishap in the original matplotlib install... so try doing the ol' get out, walk around to the back side and give it a kick... 由于您可能像我一样,并且进行了大量installing/importing ,因此在原始的matplotlib安装中可能只是一个matplotlib事情...因此,请尝试执行OL'出去,走到背面,然后踢一下...

conda uninstall matplotlib
#let it do its thing

conda install matplotlib
#let it do its thing

Then test it on the code you're trying to do and see if it works. 然后在您要执行的代码上对其进行测试,以查看其是否有效。 In my case, it came down to a "_Path" issue in my original install that messed up things. 就我而言,这归结为我的原始安装中出现了一个"_Path"问题,该问题使事情变得混乱。 After the uninstall/install , I was fine. uninstall/install ,我还好。

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

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