Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jupyter ModuleNotFoundError: No module named matplotlib

I am currently trying to work basic python - jupyter projects.

I am stuck on following error during matplotlib:

screenshot on jupyter-error enter image description here

ModuleNotFoundError: No module named 'matplotlib'

I tried to update, reinstall matplotlib aswell in conda and in pip but it still not working.

happy over every constructive feedback

like image 759
Bullfraud Avatar asked Feb 18 '17 23:02

Bullfraud


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.

How do I add matplotlib to Jupyter?

Make sure you first have Jupyter notebook installed, then we can add Matplotlib to our virtual environment. To do so, navigate to the command prompt and type pip install matplotlib. Now launch your Jupyter notebook by simply typing jupyter notebook at the command prompt.

What is matplotlib in python used for?

Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy. As such, it offers a viable open source alternative to MATLAB. Developers can also use matplotlib's APIs (Application Programming Interfaces) to embed plots in GUI applications.


3 Answers

In a Notebook's cell type and execute the code:

import sys  
!{sys.executable} -m pip install --user matplotlib

and reload the kernel

(src: http://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/ )

like image 100
Frédéric Avatar answered Oct 11 '22 07:10

Frédéric


open terminal and change the directory to Scripts folder where python installed. Then type the following command and hit enter

pip install matplotlib

Hope this will solve the issue.

like image 35
Shahriar Miraj Avatar answered Oct 11 '22 09:10

Shahriar Miraj


I was facing the exact issue. It turns out that it was using the system Python version despite me having activated my virtual environment.

This is what eventually worked.

If you are using a virtual environment which has a name say myvenv, first activate it using command:

source activate myvenv

Then install module ipykernel using the command:

pip install ipykernel

Finally run (change myvenv in code below to the name of your environment):

ipykernel install --user --name myvenv --display-name "Python (myvenv)" 

Now restart the notebook and it should pick up the Python version on your virtual environment.

like image 4
bhaskarc Avatar answered Oct 11 '22 07:10

bhaskarc