12

When importing matplotlib by import matplotlib.pyplot as plt I'm getting the following error:

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.

1
  • 9
    managed to fix it by reinstalling the whole matplotlib module. py -m pip uninstall matplotlib and then py -m pip install matplotlib Commented Feb 27, 2018 at 18:47

2 Answers 2

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

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

Comments

1

This problem can pop up when you copy libraries from place to place (at least that's what happend with me :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

(in this example I am using python 3.7.1 and matplotlib 3.0.2)

If that's not the case, reinstall matplotlib like other users suggested. Make sure also that you are targeting the correct directory (sometimes I've seen that the problem might be the wrong version of pip)

Comments

Your Answer

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