0

I am importing matplotlib from Jupyter Notebook but get the following error.

ImportError: No module named matplotlib

Settings:

Python 2 MacBook
conda: 4.3.30

After run

conda list

it got:

ipykernel 4.6.1
ipython 5.3.0
matplotlib 2.0.2 np112py36_0
matplotlib 2.1.1

Some commends I tried but failed

1.

sudo apt-get install python-matplotlib

and shows

sudo: apt-get: command not found

2.

sudo apt-get install python3-matplotlib

and shows

sudo: apt-get: command not found

commends 1 and 2 are from this site

ImportError: No module named matplotlib with matplotlib installed

3.

pip install matplotlib

and shows

Requirement already satisfied: matplotlib in ./anaconda/lib/python3.6/site-packages Requirement already satisfied: pytz in ./anaconda/lib/python3.6/site-packages (from matplotlib) Requirement already satisfied: cycler>=0.10 in ./anaconda/lib/python3.6/site-packages (from matplotlib) Requirement already satisfied: numpy>=1.7.1 in ./anaconda/lib/python3.6/site-packages (from matplotlib) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in ./anaconda/lib/python3.6/site-packages (from matplotlib) Requirement already satisfied: six>=1.10 in ./anaconda/lib/python3.6/site-packages (from matplotlib) Requirement already satisfied: python-dateutil>=2.0 in ./anaconda/lib/python3.6/site-packages (from matplotlib)

commend 3 from this website

ImportError: No module named matplotlib.pyplot

Update:

run this

pip2 install matplotlib

it was successfully installed like this

Collecting matplotlib Downloading matplotlib-2.1.1-cp27-cp27m... ... Successfully built subprocess32 Installing collected packages: subprocess32, six, python-dateutil, backports.functools-lru-cache, pyparsing, cycler, numpy, pytz, matplotlib Successfully installed backports.functools-lru-cache-1.4 cycler-0.10.0 matplotlib-2.1.1 numpy-1.13.3 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2017.3 six-1.11.0 subprocess32-3.2.7

then restart Anaconda and Jupyter, and it was not imported.

3
  • what are the outputs of which python and which pip? Commented Jan 5, 2018 at 1:57
  • Hi @PaulH I run "pip install matplotlib" on python 3 (it was not necessary though); and "pip2 install matplotlib" on python 2. Restart and it was not imported. Commented Jan 5, 2018 at 2:10
  • doesn't answer my question Commented Jan 5, 2018 at 5:18

1 Answer 1

0

By the looks of it you already have matplot lib installed for python3.6, just run with python3.6 instead of python, which ends up running python2.

pip will also normally install packages for python2 so if you want to install them for python3 use pip3 install <package>

since apt-get can not be found you are probably running CentOS which uses yum instead as the default package manager. To install you'd normally use the following command:

yum install <packagename>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for replying! My objective is to install matplotlib for python 2 on Jupyter. So I use pip2 install matplotlib, and the terminal shows Requirement already satisfied, but Jupyter could not import it somehow. Plus, the matplotlib works in text editor. P.S. Yum command not found.
If your aim is to use python 2 then you need matplotlib installed for python2 and you also need to pip install jupyter so that it uses python2 and possibly uninstall it with pip3 if you installed it there to avoid other possible conflicts. Then try running jupyter and using matplotlib
@mental , please have a look at this one - stackoverflow.com/questions/68789254/…

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.