3

I came across an ImportError in the importing of matplotlib.pyplot on Windows 10 Pro

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.

6
  • How did you install Python and MPL and on what platform? This is quite confusing? \AppData\Roaming\ ??? Commented Apr 7, 2018 at 22:09
  • Something went wrong with your matplotlib built.Did you google this error or search for it here on SO? In how far are other answers not helpful? Commented Apr 7, 2018 at 22:10
  • @dartdog Windows 10 Commented Apr 7, 2018 at 22:13
  • The 1st part of the question was how did you do the install??.. You have something very non-standard in the way you have installed,, I'd suggest starting over with Anaconda Commented Apr 7, 2018 at 22:15
  • @dartdog I used the command: python -mpip install -U matplotlib on Command Prompt Commented Apr 7, 2018 at 22:16

3 Answers 3

2

It can be a problem related to matplotlib version. 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:

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:

 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!:)

Sign up to request clarification or add additional context in comments.

Comments

1

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...

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. After the uninstall/install, I was fine.

Comments

0

Dunno what mpip is,, or why,, try plain old pip (or in your case perhaps pip3 ? This may have more to do with how the base Python was installed though,, why I suggest using Anaconda to install all (which automatically installs MPL as well..)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.