3

I am working on jupyter and python 2. When I try to use this command from matplotlib import pyplot as plt

in jupyter notebook it shoes this error

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

/home/adarsh/.local/lib/python2.7/site-packages/matplotlib/__init__.py in <module>()
    124 # cbook must import matplotlib only within function
    125 # definitions, so it is safe to import from it here.
--> 126 from . import cbook
    127 from matplotlib.cbook import (
    128     _backports, mplDeprecation, dedent, get_label, sanitize_sequence)

ImportError: cannot import name cbook

I use ubuntu

Any idea how to fix it ?

Adarsh Bahadur
  • 83
  • 3
  • 12
  • 1
    Have a look at [this question](https://stackoverflow.com/questions/44623376/importerror-cannot-import-name-cbook). – FK82 Sep 09 '18 at 09:12

2 Answers2

2

Try updating matplotlib

python -m pip install -U matplotlib

If this doesn't work, try uninstalling and reinstalling it

python -m pip uninstall matplotlib

then

python -m pip install -U matplotlib

Let me know if this fixes it.

A. Ner
  • 71
  • 3
-1

my simple advice, create a virtual environment in python and there install matplotlib.

and please shift to python3 or else you will get less answers of your problems. try using spyder or pycharm more.

try uninstalling matplotlib and six. then

conda install six=1.10.0
conda install matplotlib=2.0.2 

may this works. don't tell you don't use anaconda.

Jainil Patel
  • 1,284
  • 7
  • 16