6

I am using a windows10 machine and using PyCharm as my IDE, so when I tried to run the below code, it shows the following error

I tried uninstalling and re-installing matplotlib and also as someone from SO suggested used --force reinstall too, but didn't work

It was working well until yesterday

import matplotlib.pyplot as plt
import numpy as np

 rng = np.random.RandomState(42)
 X = 10 * rng.rand(50)
 y = 2 * X - 1 + rng.randn(50)

plt.scatter(X, y)
plt.show()

Error showing on both Pycharm and Vs Code

Traceback (most recent call last):
File "D:/PyCharm/exercise/numpy_exercise/pandas_py.py", line 1, in 
<module>
import matplotlib.pyplot as plt
File "C:\Users\smile\AppData\Roaming\Python\Python37\site- 
packages\matplotlib\__init__.py", line 143, in <module>
from matplotlib import ft2font
ImportError: cannot import name 'ft2font' from 'matplotlib' 
 (C:\Users\smile\AppData\Roaming\Python\Python37\site- 
 packages\matplotlib\__init__.py)

 Error showing on Jupyter Notebook

<ipython-input-1-1842680e3d86> in <module>
  1 import pandas as pd
  2 import numpy as np
    ----> 3 import matplotlib.pyplot as plt
  4 get_ipython().run_line_magic('matplotlib', 'inline')
  5 

 ~\AppData\Roaming\Python\Python37\site-packages\matplotlib\pyplot.py in 
 <module>
 30 from cycler import cycler
 31 import matplotlib
   ---> 32 import matplotlib.colorbar
 33 import matplotlib.image
 34 from matplotlib import rcsetup, style

 ~\AppData\Roaming\Python\Python37\site-packages\matplotlib\colorbar.py 
 in <module>
 25 
 26 import matplotlib as mpl
 ---> 27 import matplotlib.artist as martist
 28 import matplotlib.cbook as cbook
 29 import matplotlib.collections as collections

 ModuleNotFoundError: No module named 'matplotlib.artist'

2 Answers 2

8

I had a similar problem which was solved simply by forcing the reinstall of matplotlib:

python -m pip install -I matplotlib
  • The python -m pip instead of pip install to make sure the correct python executable is used
  • The -I forces reinstall
Sign up to request clarification or add additional context in comments.

Comments

5

I believe i had a similar issue - https://github.com/matplotlib/jupyter-matplotlib/issues/155 - It could be that you are using python installed from a different source (appstore or from python.org?). I suspect the issue is that your kernel is using a different python than it was a few days ago.

try deleting the Python folder in: Users\smile\AppData\Roaming\Python\Python37\site-packages\matplotlib__init__.py) and run again.

2 Comments

Great,I deleted all matplot lib folders from the said path and it started working.Found this post after long search but worth it.
Reason of this problem is that I uninstall python and reinstall it,so error happens,thx

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.