I am currently trying to work basic python - jupyter projects.
I am stuck on following error during matplotlib:
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
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/ )
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.
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.
The issue with me was that jupyter was taking python3 for me, you can always check the version of python jupyter is running on by looking on the top right corner (attached screenshot).
When I was doing pip install it was installing the dependencies for python 2.7 which is installed on mac by default. It got solved by doing:
> pip3 install matplotlib
generally speaking you should try to work within python virtual environments. and once you do that, you then need to tell JupyterLab about it. for example:
# create a virtual environment
# use the exact python you want to work with in this step
python3.9 -m venv myvenv
# 'activate' (or 'enter') it
source myvenv/bin/activate
# install the exact stuff you want to use in that environment
pip install matplotlib
# now tell JupyterLabs about the environment
python -m ipykernel install --user --name="myenv" --display-name="My project (myenv)"
# start it up
jupyter notebook mynotebook
# if you now look under 'Kernel->Change kernel', your 'myenv' should be there
# select it (restart kernel etc if needed) and you should be good
Having the same issue, installing matplotlib before to create the virtualenv solved it for me. Then I created the virtual environment and installed matplotlib on it before to start jupyter notebook.
print(sys.executable)
this gave me the following /Users/myusername/opt/anaconda3/bin/python
open terminal, go into the folder /Users/myusername/opt/anaconda3/bin/
type the following: python3 -m pip install matplotlib
restart jupyter notebook (mine is vs code mac ox)
You might need to specify the module:
python -m jupyter notebook
and this is also works
sudo jupyter notebook --allow-root
While @Frederic's top-voted solution is based on JakeVDP's blog post from 2017 , it completely neglects the %pip
magic command mentioned in the blog post. Since 2017, that has landed in mainline IPython and the easiest way to access the correct pip
instance connected to your current IPython kernel and environment from within a Jupyter notebook is to do
%pip install matplotlib
Take a look at the list of currently available magic commands at IPython's docs .
Check the python version:
$python --version
or
$python3 --version
Try installing "matplotlib" using sudo:
For python version 2.7
$sudo pip install matplotlib
or
For python version 3.x
$sudo pip3 install matplotlib
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.