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

Rus*_*hie 22 python macos matplotlib

我知道之前已经提出过这个完全相同的问题.我确实遵循了那里答案中给出的指示,并没有解决我的问题(我没有足够的声誉来评论该线程中的Q或A).无论如何,这是正在发生的事情:

我尝试做:

import matplotlib.pyplot
Run Code Online (Sandbox Code Playgroud)

作为回报,我得到:

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
Run Code Online (Sandbox Code Playgroud)

我的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)]
Run Code Online (Sandbox Code Playgroud)

编辑:

cel的建议奏效了!我刚试过"conda remove matplotlib","pip install matplotlib",然后"conda install matplotlib",并且presto!伙计,你不知道这个问题困扰了我多久.祝福你们.

cel*_*cel 21

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

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

以上陈述一般都是正确的.如果您使用condapython发行版,通常不那么复杂:

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

对于numpy,scipy,matplotlib还有更多我会建议尝试conda search <library name>首先看是否有一个conda符合您需求的配方.对于大多数用户来说conda install <library name>将是一个更好的选择pip install.

为了确保只conda安装了版本,你可以做到

conda remove matplotlib
pip uninstall matplotlib
conda install matplotlib
Run Code Online (Sandbox Code Playgroud)

之后这个问题不再出现了.