I use Eclipse + Pydev to develop my python examples. But one day when I am coding a Matplotlib example in the Eclipse PyDev project, and when I run the example, I meet the following error messages. This article will tell you how to fix it.
1. ModuleNotFoundError: No Module Named ‘matplotlib.pyplot’; ‘matplotlib’ Is Not A Package.
- Below are the detailed error messages.
Traceback (most recent call last): File "D:\Work\dev2qa.com-example-code\PythonExampleProject\com\dev2qa\example\code_learner_dot_com_example\matplotlib.py", line 7, in <module> import matplotlib.pyplot as plt File "D:\Work\dev2qa.com-example-code\PythonExampleProject\com\dev2qa\example\code_learner_dot_com_example\matplotlib.py", line 7, in <module> import matplotlib.pyplot as plt ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
2.How To Fix ModuleNotFoundError: No Module Named ‘matplotlib.pyplot’; ‘matplotlib’ Is Not A Package.
- First, you should make sure the python Matplotlib module has been installed, you can refer to the article Python 3 Matplotlib Draw Point/Line Example section 1. Verify matplotlib Has Been Installed.
- Then you should confirm that you have added the Matplotlib library in your Eclipse PyDev project Python interpreter. You can refer to the article How To Add Library In Python Eclipse Project to learn more.
- But in my example, the error still exists. I finally find that the reason is that my example python file name is matplotlib.py, so when I run the example file, the imports code import matplotlib.pyplot as plt will import the pyplot class from the current example module file, but there does not have the pyplot class in the example module, so the error occurred.
- So I change the example python file name to matplotlib_example.py, then the error has been fixed.
- what a simple and silly error.