2017-05-24 21 views
3

pyplotでグラフをプロットしようとすると、私は次のコードを実行しています:matplotlibのはAttributeError:「モジュール」オブジェクトが属性「popall」を持っていない

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はうまくいきましたが、昨日homebrewとpipを使って再インストールしたところ、このエラーが発生しました。私は次のことを実行しています:

OS: Mac OS Sierra 10.12.5 
Python: 2.7.13 
Matplotlib: 2.0.2 

私は以来、再びmatplotlibのとPythonの完全な再インストールを試みたが、まだ同じエラーを取得しています。私も複数のエディタ(Jupiter、Sublime、Terminal)を試しました。

ご協力いただければ幸いです。

+0

奇数を、'。間違って読み込まれているローカルディレクトリに 'cbook.py'というファイルがありますか? – tom

+0

matplotlibフォルダ以外のcbook.pyというファイルはありません。私はそれを開いて、 'popall'が定義されています。 1つは/usr/local/lib/python2.7/site-packages/matplotlibに、もう1つは/ usr/local/Cellar/matplotlibにありますが、2つのmatplotlibフォルダがあります。私はすべてがセラーから来ることを期待していたので、最初を取り除こうとしました。これは潜在的にPATHの問題を意味するでしょうか? homebrewの.bash_profileのパスは 'export PATH =/usr/local/bin:/ usr/local/sbin:$ PATH'です。返信いただきありがとうございます。 –

+0

不明な点、ごめんなさい。Pythonセッションで 'matplotlib.cbook'をインポートし、(a)どこからインポートされているかを確認し、(b)' popall'関数があるかどうかを調べることができます – tom

答えて

1

私は自分の問題を解決しましたが、なぜこれが解決したのか完全にはわかりません。

私はPythonがインストール、削除し、pip uninstall matplotlibを使用し、また含むように私の~/.zshrc~/.bash_profileパスを更新:Pythonの

​​

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

自作

これはiを解決しましたssue。私はこの問題が、2つのmatplotlibをインストールし、~/.bash_proileにパスを持っているが、~/.zshrcをインストールしていないことが原因であると推測しています。

1

私はこの正確なエラーがありました。私のケースではpipcondaの両方にmatplotlibのコピーがインストールされていることが判明しました。 Anchondaのギャップを埋めるために使用されるpipという混在環境では、インストールを依頼したパッケージの(既にインストールされている)依存関係へのアップグレードを自動的にインストールして複製を作成することができます。

$ conda list matplotlib 
# packages in environment at /home/ec2-user/anaconda3: 
# 
matplotlib    2.0.2    np113py35_0 
matplotlib    2.1.1      <pip> 

問題:これをテストするには

!修正:

$ pip uninstall matplotlib 

はおそらくバージョンpipmatplotlibアップグレードを強制するのは良いアイデアが欲しかった:popall`が長時間 `matplotlib.cbook`モジュールに存在している

$ conda install matplotlib=2.1.1 
関連する問題