0
votes

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.

1
what are the outputs of which python and which pip?Paul H
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.JustAnotherJavaDeveloper
doesn't answer my questionPaul H

1 Answers

0
votes

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>