I was just about to try out matplotlib for the first time, but I’ve run into a problem before I’ve even gotten started. I copied this code:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x))
plt.plot(x, np.cos(x))
plt.show()
as a sort of hello world to see how things work, but PyCharm is showing a red error in the import statements:
When I try to run the code I get
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I have no idea how this could be happening, and I didn’t even write this script myself, so I thought maybe it was an issue with the package installation, but I uninstalled and reinstalled it and nothing changed.
It seems to resemble this and this, but both cases use Visual Studio not PyCharm, the answer to the first one seems to be specific to Visual Studio and the second one I can’t understand enough to tell if it’s a match.
I have never had this issue importing other packages.
3
Did you install Matplotlib? You can install it using this command-
pip install matplotlib
Bijoy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1