Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jupyter notebook import error: no module named 'matplotlib'

I'm an ubuntu 16.4 user and I installed anaconda3 and using both python2 and python3 kernels.

>>>jupyter kernelspec list Available kernels: python2 /home/peterkim/.local/share/jupyter/kernels/python2 python3 /home/peterkim/anaconda3/share/jupyter/kernels/python3

and.. the problem was that I don't know where/how to install packages in order to for my python2 jupyter notebook not to make error 'no module named ...'. I tried pip install matplotlib and conda install matplotlib and I also appended '/home//anaconda2/pkgs' to the sys.path.

(I also installed anaconda2 in search of the way of using parallel kernels. After I realised that anaconda2 was not needed. but I didn't uninstall it.)

screenshot

like image 318
Peter Kim Avatar asked Apr 16 '17 13:04

Peter Kim


2 Answers

When using python3 version of jupyter (pip3 install jupyter), matplotlib has to be installed using pip3: pip3 install matplotlib

like image 105
logcat Avatar answered Oct 04 '22 16:10

logcat


For those still looking for a solution, especially using virtualenv, this worked for me:

1 - Inside your project directory, create a virtual environment. You may have to install virtualenv in case you don't have it

virtualenv myenv --python=python3.7

2 - Install matplotlib inside of your virtual env:

pip3 install matplotlib

3 - Install ipykernel inside your virtual env

pip3 install ipykernel

4 - Connect your jupyter kernel to your new environment. You may have to use sudo here

python3 -m ipykernel install --name=myenv

5 - When you start your jupyter lab, you will have the option to select your env, which has matplotlib installed

enter image description here

like image 38
lucianokrebs Avatar answered Oct 04 '22 17:10

lucianokrebs