问题
I have Python 2.7.6 installed under Canopy on a 64 bit Mac with Ipython version 2.1.0. This is a really odd problem and I'm not sure if it is a path file problem. Whenever I import matplotlib.pyplot (not just matplotlib), I receive the following error:
In [2]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
/Users/rpatel/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/rpatel/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/rpatel/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/rpatel/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/rpatel/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/rpatel/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: dlopen(/Users/rpatel/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/ft2font.so, 2): Symbol not found: _inflateReset2
Referenced from: /Users/rpatel/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/../../../../lib/libpng16.dylib
Expected in: /usr/lib/libz.1.dylib
in /Users/rpatel/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/../../../../lib/libpng16.dylib
I can't seem to figure out what is missing or what I need to install. Matplotlib is from the canopy distribution so I can assume it installed correctly.
回答1:
I had the identical problem, and submitted a request to Enthought for help with this and got the following solution (from Jonathan March who commented above).
From the Canopy Tools menu, open a Canopy Terminal window and call:
enpkg --no-deps matplotlib 1.2.1
enpkg --no-deps libpng 1.2.40
enpkg --no-deps freetype 2.4.4
Apparently the issue, at least for my case, is that matplotlib 1.3 refers to a library which is not in OS X 10.6. So the workaround is to downgrade matplotlib.
来源:https://stackoverflow.com/questions/24768145/matplotlib-import-error-ft2font