AttributeError: 'module' 对象没有属性 'cbook' [英] AttributeError: 'module' object has no attribute 'cbook'

查看:32
本文介绍了AttributeError: 'module' 对象没有属性 'cbook'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 导入 cv2将 numpy 导入为 np导入 matplotlib.pyplot 作为 pltx = cv2.imread('jay.jpg')plt.imshow(x, cmap = 'gray', 插值 = 'bicubic')plt.xticks([]), plt.yticks([]) # 隐藏 X 和 Y 轴上的刻度值plt.show()

错误:

 %run "c:usersjayappdatalocal	emp	mppvibq9.py"---------------------------------------------------------------------------AttributeError 回溯(最近一次调用最后一次)c:usersjayappdatalocal	emp	mppvibq9.py in <module>()2 导入 numpy 作为 np3 导入 matplotlib.cbook---->4 导入 matplotlib.pyplot 作为 plt56 x = cv2.imread('jay.jpg')C:UsersJayAppDataLocalEnthoughtCanopySystemLibsite-packagesmatplotlibpyplot.py in ()27 从循环仪进口循环仪28 导入 matplotlib--->29 导入 matplotlib.colorbar30 从 matplotlib 导入样式31 从 matplotlib 导入 _pylab_helpers,交互式C:UsersJayAppDataLocalEnthoughtCanopySystemLibsite-packagesmatplotlibcolorbar.py in ()3031 导入 matplotlib 作为 mpl--->32 导入 matplotlib.artist 作为 martist33 将 matplotlib.cbook 导入为 cbook34 导入 matplotlib.collections 作为集合C:UsersJayAppDataLocalEnthoughtCanopySystemLibsite-packagesmatplotlibartist.py in ()9 导入 numpy 作为 np10 导入 matplotlib--->11 将 matplotlib.cbook 导入为 cbook12 从 matplotlib.cbook 导入 mplDeprecation13 从 matplotlib 导入文档字符串,rcParamsAttributeError: 'module' 对象没有属性 'cbook'

我为 numpy 和 matplotlib 安装的依赖项:1.) libsvm-3.17.win64-py2.72.) pyparsing-2.0.3-1.win64-py2.73.) python-dateutil-2.4.2-2.win64-py2.74.) pytz-2015.7-1.win64-py2.75.) 6-1.10.0-1.win64-py2.76.) scipy-0.13.3.win64-py2.77.) numpy-MKL-1.9.2-2.win64-py2.78.) Matplotlib 1.5.1-win64-py2.79.) pip 8.0.2-1.win64-py2.7

解决方案

我不确定这是否会导致您的问题,但是您在错误的 Python 环境中运行代码:C:UsersJayAppDataLocalEnthoughtCanopySystem你应该运行它C:UsersJayAppDataLocalEnthoughtCanopyUser

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

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

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

解决方案

I don't know for sure that this is causing your problem, but you are running your code in the wrong Python environment: C:UsersJayAppDataLocalEnthoughtCanopySystem You should be running it in C:UsersJayAppDataLocalEnthoughtCanopyUser

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

这篇关于AttributeError: 'module' 对象没有属性 'cbook'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆