1

I'm Unable to load matplotlib in Jupyter Notebook but woking fine in python command line shell,

Is there anything I need to configure to make it working?

Following is the error I'm getting in Jupyter Notebook

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-99ba79ecbbfb> in <module>()
----> 1 from matplotlib import pyplot as plt

ImportError: No module named matplotlib

And in command line I can access it like the following:

Python 3.7.3 (default, Mar 27 2019, 23:47:09) 
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from matplotlib import pyplot as plt
>>> 
Unnikrishnan
  • 2,683
  • 5
  • 22
  • 39

3 Answers3

2

Seems like it's working now I ran the following command as specified here

python3 -m pip install ipykernel
python3 -m ipykernel install --user

Thanks.

Unnikrishnan
  • 2,683
  • 5
  • 22
  • 39
0

One way is to check if you installed matplotlib using pip3 (if you used pip3 to install jupyter notebook, which looks like is your case).

Another way is to add the path of site-wide packages (where of course matplotlib is installed). In your Jupyter notebook console:

import sys
PATH = '/usr/lib64/python3.7/site-packages/'
sys.path.append(PATH)
R4444
  • 2,016
  • 2
  • 19
  • 30
  • I have installed jupyter notebook using pip3 but it's showing the following in the about page `The version of the notebook server is: 5.7.8 The server is running on this version of Python: Python 2.7.16 (default, Mar 4 2019, 09:01:38) [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]`, How I can make it working as python3. I created the new book as python3 but still it's executing as python2.7 – Unnikrishnan Aug 09 '19 at 12:26
  • can you see? `jupyter kernelspec list` – R4444 Aug 09 '19 at 12:39
  • `Available kernels: python2 /usr/local/share/jupyter/kernels/python2 python3 /usr/local/share/jupyter/kernels/python3` – Unnikrishnan Aug 09 '19 at 12:44
  • install with: `python3 -m pip install --upgrade pip` && `python3 -m pip install jupyter` - including ipython - `pip3 install --upgrade pip jupyter ipython` – R4444 Aug 09 '19 at 12:47
  • still it's same – Unnikrishnan Aug 09 '19 at 12:53
0

Notebook is launched from another virtual python environment.

You can check paths to python interpreters, that run your notebook and interactive shell:

import sys
print(sys.executable)

I'm sure, they will be different.

wl2776
  • 4,099
  • 4
  • 35
  • 77
  • Yes it's different `/usr/local/opt/python@2/bin/python2.7` but I created this book as python3 also I tried to change it to python3 from the `kernel` menu. How i can make it working as python3 – Unnikrishnan Aug 09 '19 at 12:24