导入matplotlib.pyplot时出错

时间:2012-11-08 15:44:23

标签: python macos matplotlib enthought

当我运行import matplotlib.pyplot as plt时,收到以下错误消息:

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

/Library/Python/2.7/site-packages/matplotlib/pyplot.py in <module>()
     21 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
     22 from matplotlib import docstring
---> 23 from matplotlib.figure import Figure, figaspect
     24 from matplotlib.backend_bases import FigureCanvasBase
     25 from matplotlib.image import imread as _imread

/Library/Python/2.7/site-packages/matplotlib/figure.py in <module>()
     16 import artist
     17 from artist import Artist, allow_rasterization
---> 18 from axes import Axes, SubplotBase, subplot_class_factory
     19 from cbook import flatten, allequal, Stack, iterable, is_string_like
     20 import _image

/Library/Python/2.7/site-packages/matplotlib/axes.py in <module>()
     12 import matplotlib.artist as martist
     13 from matplotlib.artist import allow_rasterization
---> 14 import matplotlib.axis as maxis
     15 import matplotlib.cbook as cbook
     16 import matplotlib.collections as mcoll

/Library/Python/2.7/site-packages/matplotlib/axis.py in <module>()
      8 from matplotlib.artist import allow_rasterization
      9 import matplotlib.cbook as cbook
---> 10 import matplotlib.font_manager as font_manager
     11 import matplotlib.lines as mlines
     12 import matplotlib.patches as mpatches

/Library/Python/2.7/site-packages/matplotlib/font_manager.py in <module>()
     50 import matplotlib
     51 from matplotlib import afm
---> 52 from matplotlib import ft2font
     53 from matplotlib import rcParams, get_configdir
     54 from matplotlib.cbook import is_string_like

ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/ft2font.so, 2): Library not loaded: /opt/local/lib/libfreetype.6.dylib
  Referenced from: /Library/Python/2.7/site-packages/matplotlib/ft2font.so
  Reason: image not found

我的/Library/Python/2.7/site-packages/setuptools.pth就是:/Library/Frameworks/EPD64.framework/Versions/7.3/Python。我的/Library/Python/2.7/site-packages/easy-install.pth如下:

import sys; sys.__plen = len(sys.path)
./pip-1.2.1-py2.7.egg
/Library/Frameworks/EPD64.framework/Versions/7.3/Python
./pudb-2012.3-py2.7.egg
./Pygments-1.5-py2.7.egg
./urwid-1.0.2-py2.7-macosx-10.8-intel.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)

我应该如何正确导入matplotlib.pyplot?我安装了自制软件,正在运行Enthought Python Distribution,并且正在运行OSX。

1 个答案:

答案 0 :(得分:2)

我修好了!我做的是以下内容:我删除了(在备份后)我系统的site-packages文件夹(/Library/Python/2.7/site-packages)中的matplotlib文件夹。