7

I am trying to run a simple code and I have all the dependencies for matplotlib and numpy installed in my Canopy. Still I am getting error.

    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    x = cv2.imread('jay.jpg')
    plt.imshow(x, cmap = 'gray', interpolation = 'bicubic')
    plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
    plt.show()

Error:

     %run "c:\users\jay\appdata\local\temp\tmppvibq9.py"
     ---------------------------------------------------------------------------
     AttributeError                            Traceback (most recent call last)
     c:\users\jay\appdata\local\temp\tmppvibq9.py in <module>()
     2 import numpy as np
     3 import matplotlib.cbook
     ----> 4 import matplotlib.pyplot as plt
     5 
     6 x = cv2.imread('jay.jpg')

     C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\pyplot.py in <module>()
     27 from cycler import cycler
     28 import matplotlib
     ---> 29 import matplotlib.colorbar
     30 from matplotlib import style
     31 from matplotlib import _pylab_helpers, interactive

     C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\colorbar.py in <module>()
     30 
     31 import matplotlib as mpl
     ---> 32 import matplotlib.artist as martist
     33 import matplotlib.cbook as cbook
     34 import matplotlib.collections as collections

     C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\artist.py in <module>()
     9 import numpy as np
     10 import matplotlib
     ---> 11 import matplotlib.cbook as cbook
     12 from matplotlib.cbook import mplDeprecation
     13 from matplotlib import docstring, rcParams

     AttributeError: 'module' object has no attribute 'cbook'

Dependencies I have installed for numpy and matplotlib: 1.) libsvm-3.17.win64-py2.7 2.) pyparsing-2.0.3-1.win64-py2.7 3.) python-dateutil-2.4.2-2.win64-py2.7 4.) pytz-2015.7-1.win64-py2.7 5.) six-1.10.0-1.win64-py2.7 6.) scipy-0.13.3.win64-py2.7 7.) numpy-MKL-1.9.2-2.win64-py2.7 8.) Matplotlib 1.5.1-win64-py2.7 9.) pip 8.0.2-1.win64-py2.7

meJayu
  • 85
  • 1
  • 2
  • 6

5 Answers5

20

Try this:

  1. Close your jupyter notebook and terminate ipython.
  2. Restart Terminal
  3. Enter this command in Terminal:

export LANG=en_US.UTF-8;export LC_ALL=en_US.UTF-8
  1. Re-run your ipython / Jupyter notebook now. It works like a charm.
Joe C
  • 15,324
  • 8
  • 38
  • 50
  • 3
    Please elaborate on how step 3 will help the user. – Joe C Jan 22 '17 at 22:21
  • 5
    what does this do? – mrjrdnthms Jul 18 '17 at 22:49
  • 1
    This helped... I'd love to understand why, particularly so I could then suggest a more permanent solution. – Mark McDonald Dec 10 '18 at 02:49
  • In short, this will restart the python / Jupyter notebook , and set the text coding to UTF-8, which may be the cause for many of you, ( my problem was that I forget to restart the notebook after re-install a package ) – Y00 Nov 03 '19 at 22:32
1
conda install matplotlib --force
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
0

You can find which 'matplotlib.py' is imported and then open that file and check if it has 'cbook' or not.

import imp
imp.find_module("matplotlib")
AlokThakur
  • 3,599
  • 1
  • 19
  • 32
  • I could see the cbook.py here (C:\Users\Jay\AppData\Local\Enthought\Canopy\User\Lib\site-packages\matplotlib) in matplotlib folder.. still it is not working. – meJayu Feb 07 '16 at 04:34
0

I don't know for sure that this is causing your problem, but you are running your code in the wrong Python environment: C:\Users\Jay\AppData\Local\Enthought\Canopy\System\ You should be running it in C:\Users\Jay\AppData\Local\Enthought\Canopy\User

See https://support.enthought.com/entries/23646538-Make-Canopy-User-Python-be-your-default-Python

and http://docs.enthought.com/canopy/configure/faq.html#where-are-all-of-the-python-packages-in-my-user-python-environment

Jonathan March
  • 5,800
  • 2
  • 14
  • 16
0

i had the same problem and it was because of this line : from sys import stdout i deleted this import and the problem is gone now

jiar
  • 1
  • 1
  • 2