shaare.it

ImportError: No module named 'pyplot'

ImportError: No module named ‘pyplot’

$ python -c "from matplotlib import pyplot as plt"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'pyplot'

Why this happens

Matplotlib is not installed in the current environment, or you’re shadowing the matplotlib package with a local file or folder named matplotlib.

Fix

Install Matplotlib in the active environment and ensure there is no local matplotlib/ directory or matplotlib.py file.

Wrong code

from matplotlib import pyplot as plt
plt.plot([1, 2, 3])

Fixed code

# Install first: pip install matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.show()