import matplotlib.pyplot给出了ImportError:dlopen(...)库未加载libpng15.15.dylib

时间:2015-03-04 06:53:54

标签: python macos matplotlib

I am aware that this exact same question has been asked before.我确实按照那里的答案给出了指示,但它并没有解决我的问题(而且我没有足够的声誉来评论那里的问题或答案线)。无论如何,这里发生了什么:

我尝试做:

import matplotlib.pyplot

作为回报,我得到:

Traceback (most recent call last):
  File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3032, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-eff513f636fd>", line 1, in <module>
    import matplotlib.pyplot as plt
  File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
    import matplotlib.colorbar
  File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py", line 34, in <module>
    import matplotlib.collections as collections
  File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/collections.py", line 27, in <module>
    import matplotlib.backend_bases as backend_bases
  File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 56, in <module>
    import matplotlib.textpath as textpath
  File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py", line 22, in <module>
    from matplotlib.mathtext import MathTextParser
  File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py", line 63, in <module>
    import matplotlib._png as _png
ImportError: dlopen(/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: libpng15.15.dylib
  Referenced from: /Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
  Reason: image not found

我的Python版本:

2.7.7 |Anaconda 2.0.1 (x86_64)| (default, Jun  2 2014, 12:48:16) [GCC 4.0.1 (Apple Inc. build 5493)]

编辑:

cel的建议奏效了!我刚试过&#34; conda删除matplotlib&#34;,&#34; pip install matplotlib&#34;,然后&#34; conda install matplotlib&#34;,并且presto!伙计,你不知道这个问题困扰了我多久。祝福你们。

3 个答案:

答案 0 :(得分:21)

一些python包动态链接到本机c库。更新其中一个库后,链接可能会中断,并为您提供有关缺少动态库的奇怪错误消息,如问题中的错误消息所示。

基本上,在更新本机库之后,有时您还必须重建python包(此处​​为matplotlib)。

以上陈述一般都是正确的。如果您使用conda作为python发行版,那么事情往往不那么复杂:

对于扩展程序包conda,还维护必需的c库。只要您仅使用conda installconda update来安装这些软件包,就不应该遇到这些问题。

对于numpyscipymatplotlib等等,我建议首先尝试conda search <library name>,看看是否有符合您需求的conda食谱。对于大多数用户来说,conda install <library name>将是比pip install更好的选择。

要确保只安装conda版本,您可以

conda remove matplotlib
pip uninstall matplotlib
conda install matplotlib

之后不再出现此问题。

答案 1 :(得分:2)

我也遇到了这个问题。我更新了我的Anaconda-Navigator,下次我用matplotlib.pyplot打开一个项目时,我遇到了类似的问题。对我有用的是:

conda install libpng

答案 2 :(得分:1)

I had this problem, but it was because I had set

export DYLD_LIBRARY_PATH="/Users/charlesmartin14/anaconda/lib":$DYLD_LIBRARY_PATH

removing this setting and restarting the shell fixed it