17

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

Trenton McKinney
63.1k41 gold badges169 silver badges210 bronze badges
asked Apr 16, 2017 at 13:43
2
  • 1
    first of all, I would got for one python Version. Preferably the Python3 Version. Uninstall Conda with conda install anaconda-cleanand re-install Commented Apr 16, 2017 at 13:46
  • @Confidence it worked for me. Thumbs Up. Commented Jan 8, 2020 at 20:26

9 Answers 9

16

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

answered Jul 12, 2017 at 9:05

Comments

11

I'd recommend reading through here:

https://conda.io/docs/py2or3.html

I had the same problem after installing a Python 2.7 environment inside my Anaconda3 installation. I'm not sure which command I used to create the environment, but it actually didn't install all the optional packages that are usually bundled with Anaconda (like matplotlib, numpy, ...). But that's not a big issue, you can easily install additional packages with pip as follows:

First, list your conda environments:

C:\Users\Felix>conda info --envs
# conda environments:
#
ipykernel_py2 D:\Anaconda\envs\ipykernel_py2
root * D:\Anaconda

Next, activate your python 2 environment using source activate <env> (Linux/OSX) or activate <env> (Windows):

C:\Users\Felix>activate ipykernel_py2
(ipykernel_py2) C:\Users\Felix>

Finally, use pip to install the required packages:

(ipykernel_py2) C:\Users\Felix>pip install matplotlib
Collecting matplotlib
...
Successfully installed matplotlib-2.0.0

Hope that this helps.

answered Apr 16, 2017 at 22:57

1 Comment

I followed this exactly, but did not resolve my issue. I verified my pacakge is installed "(env) pipi list". Jupyter notebook executed from same env, but still same error.
5

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

answered Jun 29, 2020 at 12:05

Comments

0

I got around it with typing the following command in the terminal:

conda install matplotlib

This will download the matplotlib package into your anaconda directory.

answered Dec 7, 2018 at 19:29

1 Comment

using python 3.7, installed anaconda3. I can see all packages in my anaconda directory/pkgs. What else I am supposed to do. Do I have to do any pip install inside my jupyter notebook for matplotlib. Or setup env etc (how?)
0

This worked for me on my windows 10 :

  1. I didn't use conda. I simply downloaded python 3.x version, then created a python 3 environment by the following command : c:\python3x\python -m venv c:\path\to\your\env.
  2. After that you can check your python version by this command python -v.
  3. Then you need to activate the python 3 environment by entering this command : env/Scripts/activate.
  4. Then install the matplotlib library by doing pip3 install matplotlib .
barbsan
3,46811 gold badges23 silver badges29 bronze badges
answered Jul 15, 2019 at 12:28

Comments

0

I have checked the version of python executable and the path from where the library is getting used:

import sys

sys.executable # to know the version of executable used

sys.path # to know from which path library is getting imported.

And then: I have installed the library in jupyter notebook cell by using pip.

pip install matplotlib

After that import started working for me.

answered Mar 29, 2020 at 17:21

Comments

0

In my case, the matplotlib conda pkg was corrupted.

conda list

First, identify all the matplotlib pkgs installed in your environment. In my case, there were 2 pkgs.

matplotlib

matplotlib-base

Now remove those using conda.

conda remove matplotlib
conda remove matplotlib-base

Now check the list again to make sure, all the pkgs removed successfully. Then reinstall them again.

conda install matplotlib
conda install matplotlib-base

You may encounter an error saying

SafetyError: The package for matplotlib-base located at /home/<yourusername>/anaconda3/pkgs/matplotlib-base-3.1.3-py37hef1b27d_0 appears to be corrupted. The path 'lib/python3.7/site-packages/matplotlib-3.1.3-py3.7-nspkg.pth' has an incorrect size. reported size: 569 bytes actual size: 570 bytes

Now you need to remove this corrupted folder, in my case, "matplotlib-base-3.1.3-py37hef1b27d_0".

Then try installing the pkgs again. It's better to run

conda remove matplotlab

again before reinstalling, to make sure anything left of those pkgs completely wiped out.

answered May 1, 2020 at 7:34

Comments

0

In windows OS, I found @melkorCba suggestion helpful. But, I have some edits:

  1. After you type conda list in conda console, you can see matplotlib listed. Do not uninstall the module yet.
  2. Go to conda GUI, launch Jupyter, clear Kernel and run the notebook again. To clear Kernel, in the Jupyter notebook, go to kernel tab > Restart and Clear Output.
answered May 11, 2022 at 3:03

Comments

0

If you use multiple Python installation, use the following in your code. This fixed the error in my case

%pip install matplotlib
answered Jun 11 at 11:16

1 Comment

A similar answer was already submitted, please add more information to bring novelty

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.