Python Matplotlib AttributeError:&x27;模块';对象没有属性';popall';

Python Matplotlib AttributeError:&x27;模块';对象没有属性';popall';,python,matplotlib,Python,Matplotlib,尝试使用pyplot绘制图形时,我正在运行以下代码: from matplotlib import pyplot as plt x = [6, 5, 4] y = [3, 4, 5] plt.plot(x, y) plt.show() 这将返回以下错误: --------------------------------------------------------------------------- AttributeError T

尝试使用pyplot绘制图形时,我正在运行以下代码:

from matplotlib import pyplot as plt

x = [6, 5, 4]
y = [3, 4, 5]

plt.plot(x, y)
plt.show()
这将返回以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-59955f73b463> in <module>()
      4 y = [3, 4, 5]
      5 
----> 6 plt.plot(x, y)
      7 plt.show()

/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.pyc in plot(*args, **kwargs)
   3304 @_autogen_docstring(Axes.plot)
   3305 def plot(*args, **kwargs):
-> 3306     ax = gca()
   3307     # Deprecated: allow callers to override the hold state
   3308     # by passing hold=True|False

/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.pyc in gca(**kwargs)
    948     matplotlib.figure.Figure.gca : The figure's gca method.
    949     """
--> 950     return gcf().gca(**kwargs)
    951 
    952 # More ways of creating axes:

/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in gca(self, **kwargs)
   1367 
   1368         # no axes found, so create one which spans the figure
-> 1369         return self.add_subplot(1, 1, 1, **kwargs)
   1370 
   1371     def sca(self, a):

/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in add_subplot(self, *args, **kwargs)
   1019                     self._axstack.remove(ax)
   1020 
-> 1021             a = subplot_class_factory(projection_class)(self, *args, **kwargs)
   1022 
   1023         self._axstack.add(key, a)

/usr/local/lib/python2.7/site-packages/matplotlib/axes/_subplots.pyc in __init__(self, fig, *args, **kwargs)
     71 
     72         # _axes_class is set in the subplot_class_factory
---> 73         self._axes_class.__init__(self, fig, self.figbox, **kwargs)
     74 
     75     def __reduce__(self):

/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in __init__(self, fig, rect, facecolor, frameon, sharex, sharey, label, xscale, yscale, axisbg, **kwargs)
    527 
    528         # this call may differ for non-sep axes, e.g., polar
--> 529         self._init_axis()
    530         if axisbg is not None and facecolor is not None:
    531             raise TypeError('Both axisbg and facecolor are not None. '

/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _init_axis(self)
    620     def _init_axis(self):
    621         "move this out of __init__ because non-separable axes don't use it"
--> 622         self.xaxis = maxis.XAxis(self)
    623         self.spines['bottom'].register_axis(self.xaxis)
    624         self.spines['top'].register_axis(self.xaxis)

/usr/local/lib/python2.7/site-packages/matplotlib/axis.pyc in __init__(self, axes, pickradius)
    674         self._minor_tick_kw = dict()
    675 
--> 676         self.cla()
    677         self._set_scale('linear')
    678 

/usr/local/lib/python2.7/site-packages/matplotlib/axis.pyc in cla(self)
    758         self._set_artist_props(self.label)
    759 
--> 760         self.reset_ticks()
    761 
    762         self.converter = None

/usr/local/lib/python2.7/site-packages/matplotlib/axis.pyc in reset_ticks(self)
    769         # define 1 so properties set on ticks will be copied as they
    770         # grow
--> 771         cbook.popall(self.majorTicks)
    772         cbook.popall(self.minorTicks)
    773 

AttributeError: 'module' object has no attribute 'popall'
此后,我再次尝试完全重新安装matplotlib和python,但仍然出现相同的错误。我还尝试了多种编辑器(Jupiter、Sublime、Terminal)


任何帮助都将不胜感激

我已经解决了我的问题,尽管我不完全确定为什么这解决了它

我使用
pip uninstall matplotlib
删除python安装,并更新了我的
~/.zshrc
~/.bash_配置文件
路径,以包含:

自制:

export PATH=/usr/local/bin:$PATH

Python:

export PATH=/usr/local/share/python:$PATH


这就解决了问题。我猜问题是由两次安装matplotlib造成的,路径位于
~/.bash_proile
中,而不是
~/.zshrc

我有一个确切的错误,在我的例子中,结果是
pip
conda
都安装了
matplotlib
的副本。在“混合”环境中,
pip
用于填补Anaconda中的空白,
pip
可以自动安装升级到您要求安装的软件包(已安装)的依赖项,从而创建重复

要对此进行测试,请执行以下操作:

$ conda list matplotlib
# packages in environment at /home/ec2-user/anaconda3:
# 
matplotlib                2.0.2               np113py35_0
matplotlib                2.1.1                     <pip>
强制
matplotlib
升级到所需的
pip
版本可能是个好主意:

$ conda install matplotlib=2.1.1

我也有类似的问题 我所做的是尝试使用

pip install -U matplotlib

然后重新打开anaconda,查看它的工作情况。奇怪的是,
popall
matplotlib.cbook
模块中已经存在很长时间了。您的本地目录中是否有一个名为
cbook.py
的文件被错误读取?除了matplotlib文件夹外,我没有其他名为cbook.py的文件。我已经打开了它,在那里定义了
popall
。我有两个matplotlib文件夹,其中一个位于/usr/local/lib/python2.7/site-packages/matplotlib中,另一个位于/usr/local/cillar/matplotlib中。我已经试着把第一个拿走,因为我希望所有东西都能从地窖里出来。这是否意味着可能存在路径问题?我的自制.bash_配置文件路径是:
导出路径=/usr/local/bin:/usr/local/sbin:$path
。非常感谢你的回复。那就不确定了,对不起。您可以尝试在python会话中导入
matplotlib.cbook
,并检查(a)它从何处导入,以及(b)它是否具有
popall
函数(+1)-我还必须指定获取所需版本的通道:
conda安装-c anaconda matplotlib
$ conda install matplotlib=2.1.1
pip install -U matplotlib