Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

Have found a similar issue, however haven't found proper solution.

Here's a code:

import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,2,5])
plt.show()

Run, got the message:

ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

I run Linux Mint 18 with preinstalled python-2.7 and python-3.5 (I use python3), before that I was installing modules with a simple sudo apt-get install method and that worked great.

Before running this the code above, I've installed matplotlib in a usual way sudo apt-get install python-matplotlib. As it haven't worked out, started to look for solution.

Python location

which python3 /usr/bin/python3

Current Matplotlib installed

sudo find /usr | grep matplotlib /usr/lib/python3/dist-packages/matplotlib

My tries:

1) I've removed matplotlib with autoremove, and tried to make it sudo apt-get install python3-matplotlib instead. Didn't worked out.

2) Used: pip3 install matplotlib or sudo pip3 install matplotlib. Received errors like:

command python setup.py egg_info failed with error code 1 in /tmp/pip-build- ....

3) Then I found another solution:

sudo apt-get install virtualenv
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install matplotlib

Same outcome.

Haven't tried to use import sys sys.path.append('/usr/lib/pymodules/python2.7/')(proposed in link above), but as I am not sure what exactly this command does (quite a newbie to python and programming itself) - haven't risked.

like image 907
emptypocket Avatar asked Dec 28 '16 21:12

emptypocket


People also ask

Why does matplotlib say no module?

The Python "ModuleNotFoundError: No module named 'matplotlib'" occurs when we forget to install the matplotlib module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install matplotlib command.

Why matplotlib is not installed?

Since matplotlib doesn't come installed automatically with Python, you'll need to install it yourself. The easiest way to do so is by using pip, which is a package manager for Python. In most cases, this will fix the error.

Does Python 3.10 support matplotlib?

Matplotlib 2.0. x supports Python versions 2.7 through 3.10.


1 Answers

If you are using pycharm and have matplotlib.py in your current working directory than you get this error. Just delete or rename the matplotlib.py file and it will work.

like image 62
Milan Kc Avatar answered Oct 08 '22 12:10

Milan Kc