Yosemite和Python Matplotlib问题

1 投票
1 回答
1714 浏览
提问于 2025-04-28 18:42

我之前的Python代码运行得很好,但在我升级到Yosemite之后就出问题了。有没有人知道怎么回事?以下是错误信息:

Traceback (most recent call last):
  File "/Users/will/Downloads/legend_demo4.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py", line 26, in <module>
    from matplotlib.figure import Figure, figaspect
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 32, in <module>
    from matplotlib.image import FigureImage
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/image.py", line 22, in <module>
    import matplotlib._png as _png
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: /usr/X11/lib/libpng12.0.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
  Reason: image not found
暂无标签

1 个回答

0

我之前也遇到过同样的问题。
我通过先卸载(用命令:easy_install -m matplotlib)然后重新安装(用命令:python setup.py build; python setup.py install)从源代码安装的matplotlib,最后再安装wheels包(用命令:pip install packagename.whl)来解决这个问题。

撰写回答