python - AttributeError: 'module' 对象没有属性 'cbook'

标签 python matplotlib attributeerror canopy

我正在尝试运行一个简单的代码,并且在我的 Canopy 中安装了 matplotlib 和 numpy 的所有依赖项。我仍然收到错误。

    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()

错误:

     %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'

我为 numpy 和 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.) 六-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.) 点子 8.0.2-1.win64-py2.7

最佳答案

试试这个:

  1. 关闭您的 jupyter notebook 并终止 ipython。
  2. 重启终端
  3. 在终端中输入此命令:

export LANG=en_US.UTF-8;export LC_ALL=en_US.UTF-8

  1. 现在重新运行您的 ipython/Jupyter notebook。它就像一个魅力。

关于python - AttributeError: 'module' 对象没有属性 'cbook',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35236953/

相关文章:

python - 将列表中元组形式的单行字符串拆分为多行(等于元组数)

python - 无法从 HTTP POST 请求恢复项目列表

python - 将图例中的 Matplotlib 矩形更改为圆形

python - 类中字典的 getter/setter 的正确用法——防止在设置字典元素时调用 getter

Python assertRaises 处理用户定义的异常

python - 如何旋转 matplotlib 填充样式标记?

python - 在 Jupyter Notebook 中使用 pyplot.scatter() 会导致 Jupyter Notebook 菜单出现错误

Python *args 属性错误

python - 缩放并保存图像(AttributeError : 'NoneType' object has no attribute 'shape' )

Python - 属性错误 '_io.TextIOWrapper' 对象没有属性 'open'