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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AttributeError:'module'对象没有属性'cbook'相关的知识,希望对你有一定的参考价值。

我正在尝试运行一个简单的代码,我在我的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:usersjayappdatalocal	emp	mppvibq9.py"
     ---------------------------------------------------------------------------
     AttributeError                            Traceback (most recent call last)
     c:usersjayappdatalocal	emp	mppvibq9.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:UsersJayAppDataLocalEnthoughtCanopySystemLibsite-packagesmatplotlibpyplot.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:UsersJayAppDataLocalEnthoughtCanopySystemLibsite-packagesmatplotlibcolorbar.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:UsersJayAppDataLocalEnthoughtCanopySystemLibsite-packagesmatplotlibartist.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.)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

答案

我不确定这是否会导致您的问题,但是您在错误的Python环境中运行代码:C: Users Jay AppData Local Enthought Canopy System 您应该在C中运行它:用户周杰伦应用程序数据本地 Enthought 雨棚用户

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

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

另一答案

试试这个:

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

export LANG=en_US.UTF-8;export LC_ALL=en_US.UTF-8
另一答案
conda install matplotlib --force
另一答案

您可以找到导入的“matplotlib.py”,然后打开该文件并检查它是否具有“cbook”。

import imp
imp.find_module("matplotlib")

以上是关于AttributeError:'module'对象没有属性'cbook'的主要内容,如果未能解决你的问题,请参考以下文章

解决:AttributeError: module 'requests' has no attribute 'get'”

Python 报错 AttributeError: module 'django.db.models' has no attribute 'SubfieldBase'(

AttributeError: module ‘seaborn‘ has no attribute ‘tsplot‘

python报错: AttributeError module 'time' has no attribute 'clock'

AttributeError: module 'pip' has no attribute 'main'如何解决?

AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'