2012-10-04 107 views
0

我正在尝试使用import matplotlib.pyplot as plt导入Pylab。不过,我在下面收到一条错误消息。有没有人有这方面的修复?我使用Enthought的发行版,它使用IPython 0.12。导入Pylab时出错

In [1]: import matplotlib.pyplot as plt 
--------------------------------------------------------------------------- 
ImportError        Traceback (most recent call last) 
<ipython-input-1-eff513f636fd> in <module>() 
----> 1 import matplotlib.pyplot as plt 

/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 

编辑:的ls -ltr /Library/Python/2.7/site-packages/matplotlib/输出:

total 19800 
-rw-r--r-- 1 root wheel 44538 Sep 24 21:21 widgets.py 
-rw-r--r-- 1 root wheel 5035 Sep 24 21:21 units.py 
-rw-r--r-- 1 root wheel 11537 Sep 24 21:21 type1font.py 
-rw-r--r-- 1 root wheel 77154 Sep 24 21:21 transforms.py 
-rw-r--r-- 1 root wheel 7098 Sep 24 21:21 tight_layout.py 
-rw-r--r-- 1 root wheel 3839 Sep 24 21:21 tight_bbox.py 
-rw-r--r-- 1 root wheel 51195 Sep 24 21:21 ticker.py 
-rw-r--r-- 1 root wheel 15516 Sep 24 21:21 textpath.py 
-rw-r--r-- 1 root wheel 69526 Sep 24 21:21 text.py 
-rw-r--r-- 1 root wheel 22703 Sep 24 21:21 texmanager.py 
-rw-r--r-- 1 root wheel 16868 Sep 24 21:21 table.py 
-rw-r--r-- 1 root wheel 17723 Sep 24 21:21 spines.py 
-rw-r--r-- 1 root wheel 14316 Sep 24 21:21 scale.py 
-rw-r--r-- 1 root wheel 40573 Sep 24 21:21 sankey.py 
-rw-r--r-- 1 root wheel 25707 Sep 24 21:21 rcsetup.py 
-rw-r--r-- 1 root wheel 40599 Sep 24 21:21 quiver.py 
-rw-r--r-- 1 root wheel 92531 Sep 24 21:21 pyplot.py 
-rw-r--r-- 1 root wheel 143924 Sep 24 21:21 pyparsing.py 
-rw-r--r-- 1 root wheel 11742 Sep 24 21:21 pylab.py 
-rw-r--r-- 1 root wheel 6826 Sep 24 21:21 patheffects.py 
-rw-r--r-- 1 root wheel 24453 Sep 24 21:21 path.py 
-rw-r--r-- 1 root wheel 133545 Sep 24 21:21 patches.py 
-rw-r--r-- 1 root wheel 50156 Sep 24 21:21 offsetbox.py 
-rw-r--r-- 1 root wheel  785 Sep 24 21:21 mpl.py 
-rw-r--r-- 1 root wheel 100604 Sep 24 21:21 mlab.py 
-rw-r--r-- 1 root wheel 109731 Sep 24 21:21 mathtext.py 
-rw-r--r-- 1 root wheel 23594 Sep 24 21:21 markers.py 
-rw-r--r-- 1 root wheel 38180 Sep 24 21:21 lines.py 
-rw-r--r-- 1 root wheel 20098 Sep 24 21:21 legend_handler.py 
-rw-r--r-- 1 root wheel 35251 Sep 24 21:21 legend.py 
-rw-r--r-- 1 root wheel 46614 Sep 24 21:21 image.py 
-rw-r--r-- 1 root wheel 6564 Sep 24 21:21 hatch.py 
-rw-r--r-- 1 root wheel 16092 Sep 24 21:21 gridspec.py 
-rw-r--r-- 1 root wheel 6429 Sep 24 21:21 fontconfig_pattern.py 
-rw-r--r-- 1 root wheel 43749 Sep 24 21:21 font_manager.py 
-rw-r--r-- 1 root wheel 23033 Sep 24 21:21 finance.py 
-rw-r--r-- 1 root wheel 50232 Sep 24 21:21 figure.py 
-rw-r--r-- 1 root wheel 32575 Sep 24 21:21 dviread.py 
-rw-r--r-- 1 root wheel 3769 Sep 24 21:21 docstring.py 
-rw-r--r-- 1 root wheel 40070 Sep 24 21:21 dates.py 
-rw-r--r-- 1 root wheel 54477 Sep 24 21:21 contour.py 
-rw-r--r-- 1 root wheel 2832 Sep 24 21:21 container.py 
-rw-r--r-- 1 root wheel 44186 Sep 24 21:21 colors.py 
-rw-r--r-- 1 root wheel 34547 Sep 24 21:21 colorbar.py 
-rw-r--r-- 1 root wheel 45282 Sep 24 21:21 collections.py 
-rw-r--r-- 1 root wheel 9508 Sep 24 21:21 cm.py 
-rw-r--r-- 1 root wheel 59573 Sep 24 21:21 cbook.py 
-rw-r--r-- 1 root wheel 12895 Sep 24 21:21 blocking_input.py 
-rw-r--r-- 1 root wheel 16237 Sep 24 21:21 bezier.py 
-rw-r--r-- 1 root wheel 94652 Sep 24 21:21 backend_bases.py 
-rw-r--r-- 1 root wheel 72371 Sep 24 21:21 axis.py 
-rw-r--r-- 1 root wheel 301792 Sep 24 21:21 axes.py 
-rw-r--r-- 1 root wheel 37279 Sep 24 21:21 artist.py 
-rw-r--r-- 1 root wheel 19948 Sep 24 21:21 animation.py 
-rw-r--r-- 1 root wheel 15422 Sep 24 21:21 afm.py 
-rw-r--r-- 1 root wheel 3275 Sep 24 21:21 _pylab_helpers.py 
-rw-r--r-- 1 root wheel 89917 Sep 24 21:21 _mathtext_data.py 
-rw-r--r-- 1 root wheel 88432 Sep 24 21:21 _cm.py 
-rw-r--r-- 1 root wheel 33452 Sep 24 21:21 __init__.py 
-rwxr-xr-x 1 root wheel 844488 Sep 24 21:21 ft2font.so 
-rwxr-xr-x 1 root wheel 152904 Sep 24 21:21 ttconv.so 
-rwxr-xr-x 1 root wheel 53672 Sep 24 21:21 _cntr.so 
-rwxr-xr-x 1 root wheel 35020 Sep 24 21:21 nxutils.so 
-rwxr-xr-x 1 root wheel 161740 Sep 24 21:21 _delaunay.so 
-rwxr-xr-x 1 root wheel 741008 Sep 24 21:21 _path.so 
-rwxr-xr-x 1 root wheel 693588 Sep 24 21:21 _tri.so 
-rwxr-xr-x 1 scott wheel 828348 Sep 24 21:21 _image.so copy 
-rwxr-xr-x 1 root wheel 828348 Sep 24 21:21 _image.so 
-rwxr-xr-x 1 root wheel 488096 Sep 24 21:22 _png.so 
drwxr-xr-x 7 root wheel  238 Sep 24 21:22 mpl-data 
-rw-r--r-- 1 root wheel 44944 Sep 24 21:22 widgets.pyc 
-rw-r--r-- 1 root wheel 5808 Sep 24 21:22 units.pyc 
-rw-r--r-- 1 root wheel 11090 Sep 24 21:22 type1font.pyc 
drwxr-xr-x 12 root wheel  408 Sep 24 21:22 tri 
-rw-r--r-- 1 root wheel 91307 Sep 24 21:22 transforms.pyc 
-rw-r--r-- 1 root wheel 6061 Sep 24 21:22 tight_layout.pyc 
-rw-r--r-- 1 root wheel 4172 Sep 24 21:22 tight_bbox.pyc 
-rw-r--r-- 1 root wheel 57906 Sep 24 21:22 ticker.pyc 
-rw-r--r-- 1 root wheel 14645 Sep 24 21:22 textpath.pyc 
-rw-r--r-- 1 root wheel 67364 Sep 24 21:22 text.pyc 
-rw-r--r-- 1 root wheel 19813 Sep 24 21:22 texmanager.pyc 
drwxr-xr-x 50 root wheel 1700 Sep 24 21:22 tests 
drwxr-xr-x 11 root wheel  374 Sep 24 21:22 testing 
-rw-r--r-- 1 root wheel 16758 Sep 24 21:22 table.pyc 
-rw-r--r-- 1 root wheel 15471 Sep 24 21:22 spines.pyc 
drwxr-xr-x 12 root wheel  408 Sep 24 21:22 sphinxext 
-rw-r--r-- 1 root wheel 19505 Sep 24 21:22 scale.pyc 
-rw-r--r-- 1 root wheel 26862 Sep 24 21:22 sankey.pyc 
-rw-r--r-- 1 root wheel 22428 Sep 24 21:22 rcsetup.pyc 
-rw-r--r-- 1 root wheel 35530 Sep 24 21:22 quiver.pyc 
-rw-r--r-- 1 root wheel 91567 Sep 24 21:22 pyplot.pyc 
-rw-r--r-- 1 root wheel 144868 Sep 24 21:22 pyparsing.pyc 
-rw-r--r-- 1 root wheel 13151 Sep 24 21:22 pylab.pyc 
drwxr-xr-x 8 root wheel  272 Sep 24 21:22 projections 
-rw-r--r-- 1 root wheel 7714 Sep 24 21:22 patheffects.pyc 
-rw-r--r-- 1 root wheel 22967 Sep 24 21:22 path.pyc 
-rw-r--r-- 1 root wheel 134328 Sep 24 21:22 patches.pyc 
-rw-r--r-- 1 root wheel 54567 Sep 24 21:22 offsetbox.pyc 
-rw-r--r-- 1 root wheel 1175 Sep 24 21:22 mpl.pyc 
-rw-r--r-- 1 root wheel 105969 Sep 24 21:22 mlab.pyc 
-rw-r--r-- 1 root wheel 109167 Sep 24 21:22 mathtext.pyc 
-rw-r--r-- 1 root wheel 25276 Sep 24 21:22 markers.pyc 
-rw-r--r-- 1 root wheel 41185 Sep 24 21:22 lines.pyc 
-rw-r--r-- 1 root wheel 18782 Sep 24 21:22 legend_handler.pyc 
-rw-r--r-- 1 root wheel 28941 Sep 24 21:22 legend.pyc 
-rw-r--r-- 1 root wheel 44466 Sep 24 21:22 image.pyc 
-rw-r--r-- 1 root wheel 9038 Sep 24 21:22 hatch.pyc 
-rw-r--r-- 1 root wheel 14893 Sep 24 21:22 gridspec.pyc 
-rw-r--r-- 1 root wheel 6491 Sep 24 21:22 fontconfig_pattern.pyc 
-rw-r--r-- 1 root wheel 40188 Sep 24 21:22 font_manager.pyc 
-rw-r--r-- 1 root wheel 19865 Sep 24 21:22 finance.pyc 
-rw-r--r-- 1 root wheel 51123 Sep 24 21:22 figure.pyc 
-rw-r--r-- 1 root wheel 33935 Sep 24 21:22 dviread.pyc 
-rw-r--r-- 1 root wheel 5278 Sep 24 21:22 docstring.pyc 
drwxr-xr-x 10 root wheel  340 Sep 24 21:22 delaunay 
-rw-r--r-- 1 root wheel 43998 Sep 24 21:22 dates.pyc 
-rw-r--r-- 1 root wheel 46848 Sep 24 21:22 contour.pyc 
-rw-r--r-- 1 root wheel 4997 Sep 24 21:22 container.pyc 
-rw-r--r-- 1 root wheel 43736 Sep 24 21:22 colors.pyc 
-rw-r--r-- 1 root wheel 32285 Sep 24 21:22 colorbar.pyc 
-rw-r--r-- 1 root wheel 46694 Sep 24 21:22 collections.pyc 
-rw-r--r-- 1 root wheel 10966 Sep 24 21:22 cm.pyc 
-rw-r--r-- 1 root wheel 71936 Sep 24 21:22 cbook.pyc 
-rw-r--r-- 1 root wheel 14396 Sep 24 21:22 blocking_input.pyc 
-rw-r--r-- 1 root wheel 14524 Sep 24 21:22 bezier.pyc 
drwxr-xr-x 59 root wheel 2006 Sep 24 21:22 backends 
-rw-r--r-- 1 root wheel 98700 Sep 24 21:22 backend_bases.pyc 
-rw-r--r-- 1 root wheel 68984 Sep 24 21:22 axis.pyc 
-rw-r--r-- 1 root wheel 268555 Sep 24 21:22 axes.pyc 
-rw-r--r-- 1 root wheel 40988 Sep 24 21:22 artist.pyc 
-rw-r--r-- 1 root wheel 15092 Sep 24 21:22 animation.pyc 
-rw-r--r-- 1 root wheel 16956 Sep 24 21:22 afm.pyc 
-rw-r--r-- 1 root wheel 4467 Sep 24 21:22 _pylab_helpers.pyc 
-rw-r--r-- 1 root wheel 64647 Sep 24 21:22 _mathtext_data.pyc 
-rw-r--r-- 1 root wheel 81690 Sep 24 21:22 _cm.pyc 
-rw-r--r-- 1 root wheel 32767 Sep 24 21:22 __init__.pyc 

ls -ltr /opt/local/lib/输出:

ls: /opt/local/lib/: No such file or directory 

回答

0

尝试删除您的字体缓存,并再次尝试:

rm -rf ~/.matplotlib/*cache*

或者,你将能够提供的

ls -ltr /Library/Python/2.7/site-packages/matplotlib/

输出

/opt/local/lib/

+0

完成!我也尝试过'rm'命令,但它没有做任何事情。 – Scott

1

你从系统Python的site-packages目录(进口/库/ Python/2.7/site-packages)而不是EPD的site-packages目录(/Library/Frameworks/Python.framework/Versions/Current/lib/python2.7/site-packages)。

这可能是由于系统site-packages目录中的.pth文件。这些文件导致系统site-packages目录在运行EPD的Python时添加到您的PYTHONPATH中(查看sys.path以确认)删除或以其他方式删除这些文件,您应该能够从EPD附带的matplotlib中导入。