2013-12-10 84 views
5

我是ipython筆記本的新手,但每次運行import matplotlib.pyplot as plt時都會收到以下錯誤消息。我正在使用Mac。它可以與內置的python或Canopy配合使用。該問題僅在ipython notebook存在。我也嘗試更新numpy,但問題仍然存在。會感激有人來幫忙!ipython筆記本中的「import matplotlib.pyplot as plt」

import matplotlib.pyplot as plt 

--------------------------------------------------------------------------- 
RuntimeError        Traceback (most recent call last) 
RuntimeError: module compiled against API version 9 but this version of numpy is 7 

--------------------------------------------------------------------------- 
ImportError        Traceback (most recent call last) 
<ipython-input-4-6f467123fe04> in <module>() 
----> 1 import matplotlib.pyplot 

/Users/Michael/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>() 
    22 
    23 import matplotlib 
---> 24 import matplotlib.colorbar 
    25 from matplotlib import _pylab_helpers, interactive 
    26 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike 

/Users/Michael/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>() 
    27 import matplotlib.artist as martist 
    28 import matplotlib.cbook as cbook 
---> 29 import matplotlib.collections as collections 
    30 import matplotlib.colors as colors 
    31 import matplotlib.contour as contour 

/Users/Michael/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/collections.py in <module>() 
    21 import matplotlib.artist as artist 
    22 from matplotlib.artist import allow_rasterization 
---> 23 import matplotlib.backend_bases as backend_bases 
    24 import matplotlib.path as mpath 
    25 from matplotlib import _path 

/Users/Michael/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>() 
    48 
    49 import matplotlib.tight_bbox as tight_bbox 
---> 50 import matplotlib.textpath as textpath 
    51 from matplotlib.path import Path 
    52 from matplotlib.cbook import mplDeprecation 

/Users/Michael/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/textpath.py in <module>() 
     9 from matplotlib.path import Path 
    10 from matplotlib import rcParams 
---> 11 import matplotlib.font_manager as font_manager 
    12 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING 
    13 from matplotlib.ft2font import LOAD_TARGET_LIGHT 

/Users/Michael/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/font_manager.py in <module>() 
    51 import matplotlib 
    52 from matplotlib import afm 
---> 53 from matplotlib import ft2font 
    54 from matplotlib import rcParams, get_cachedir 
    55 from matplotlib.cbook import is_string_like 

ImportError: numpy.core.multiarray failed to import 
+0

嘗試運行'ipython筆記本--pylab' – askewchan

+0

嗨,感謝您的幫助。我嘗試了下面的錯誤消息。我試圖再次安裝matplotlib,並再次運行該程序,但在ipython筆記本中仍然收到相同的錯誤消息。 '警告:試圖在virtualenv工作。如果遇到問題,請在virtualenv中安裝IPython。 ------------------------------------------------- -------------------------- 無追蹤(最近呼叫最後一個) 無:無 [IPKernelApp]警告| Eventloop或matplotlib集成失敗。是否安裝了matplotlib?' – user3084957

+1

它看起來像您的安裝是borked。看起來你是在一個mac上,似乎有路徑正確的地方性問題。你是怎麼安裝'matplotlib'/enthought? – tacaswell

回答

1

你對Canopy的態度如何?我有一些嘗試使用Canopy的配置問題,並最終使用Homebrew來自定義我自己的Python安裝。有在真正有用的指南:

http://joernhees.de/blog/2013/06/08/mac-os-x-10-8-scientific-python-with-homebrew/

我遵循了所有這些步驟,除了兩個或三個(不記得確切)中的「釀造安裝」方法沒有工作,我不得不點子該模塊,而不是。

我剛打開一個IPython筆記本來驗證我的發行版中的一切正常。

from matplotlib import pyplot as plt 
import numpy as np 

x = np.linspace(0, 2*np.pi, 100) 
y = np.sin(x) 
plt.plot(x, y) 
plt.show() 

以上給出了預期的輸出。