Error importing matplotlib.pyplot

纵饮孤独 提交于 2019-12-04 06:03:11

问题


When I run import matplotlib.pyplot as plt, I get the following error message:

---------------------------------------------------------------------------
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

My /Library/Python/2.7/site-packages/setuptools.pth is this: /Library/Frameworks/EPD64.framework/Versions/7.3/Python. My /Library/Python/2.7/site-packages/easy-install.pth is as following:

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)

What should I to import matplotlib.pyplot correctly? I have homebrew installed, am running the Enthought Python Distribution, and am running OSX.


回答1:


I fixed it! What I did was the following: I deleted (after making a backup) the matplotlib folder in my system's site-packages folder (/Library/Python/2.7/site-packages).



来源:https://stackoverflow.com/questions/13292396/error-importing-matplotlib-pyplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!