Macos import matplotlib.pyplot提供ImportError:dlopen(…)库未加载libpng15.15.dylib

Macos import matplotlib.pyplot提供ImportError:dlopen(…)库未加载libpng15.15.dylib,macos,matplotlib,libpng,Macos,Matplotlib,Libpng,导入pyplot时出现错误: In [1]: import matplotlib In [2]: import matplotlib.pyplot as plt ImportError Traceback (most recent call last) <ipython-input-2-eff513f636fd> in <module>() ----> 1 import matplotlib.pyplot

导入pyplot时出现错误:

In [1]: import matplotlib
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/r8t/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
     25
     26 import matplotlib
---> 27 import matplotlib.colorbar
     28 from matplotlib import style
     29 from matplotlib import _pylab_helpers, interactive

/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
     32 import matplotlib.artist as martist
     33 import matplotlib.cbook as cbook
---> 34 import matplotlib.collections as collections
     35 import matplotlib.colors as colors
     36 import matplotlib.contour as contour
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/collections.py in <module>()
     25 import matplotlib.artist as artist
     26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
     28 import matplotlib.path as mpath
     29 from matplotlib import _path
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>()
     54
     55 import matplotlib.tight_bbox as tight_bbox
---> 56 import matplotlib.textpath as textpath
     57 from matplotlib.path import Path
     58 from matplotlib.cbook import mplDeprecation
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py in <module>()
     20 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
     21 from matplotlib.ft2font import LOAD_TARGET_LIGHT
 ---> 22 from matplotlib.mathtext import MathTextParser
     23 import matplotlib.dviread as dviread
     24 from matplotlib.font_manager import FontProperties

/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py in <module>()
     61
     62 import matplotlib.colors as mcolors
---> 63 import matplotlib._png as _png
     64 ####################
     65
 ImportError: dlopen(/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library   not loaded: libpng15.15.dylib
  Referenced from: /Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
  Reason: image not found
[1]中的
:导入matplotlib
在[2]中:将matplotlib.pyplot作为plt导入
ImportError回溯(最近一次呼叫最后一次)
在()
---->1将matplotlib.pyplot作为plt导入
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in()
25
26导入matplotlib
--->27导入matplotlib.colorbar
28来自matplotlib导入样式
29来自matplotlib导入_pylab_帮助程序,交互式
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py in()
32导入matplotlib.artist作为martist
33将matplotlib.cbook导入为cbook
--->34将matplotlib.collections导入为集合
35导入matplotlib.colors作为颜色
36将matplotlib.contour导入为等高线
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/collections.py in()
25将matplotlib.artist作为艺术家导入
26从matplotlib.artist导入允许光栅化
--->27导入matplotlib.backend_base作为后端_base
28将matplotlib.path导入为mpath
29从matplotlib导入路径
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backend_base.py in()
54
55导入matplotlib.tight_bbox作为tight_bbox
--->56将matplotlib.textpath导入为textpath
57从matplotlib.path导入路径
58从matplotlib.cbook导入mpldeprication
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py in()
20从matplotlib.ft2font导入ft2font、紧排默认值、加载无提示
21从matplotlib.FT2导入加载目标灯
--->22从matplotlib.mathtext导入MathTextParser
23将matplotlib.dviread作为dviread导入
24从matplotlib.font_管理器导入FontProperties
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py in()
61
62将matplotlib.colors导入为MCOLOR
--->63导入matplotlib.\u png作为\u png
64 ####################
65
导入错误:dlopen(/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib//u png.so,2):未加载库:libpng15.15.dylib
引用自:/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib//u png.so
原因:找不到图像
我看过 这建议删除matplotlib文件夹。我试过了,但没用。这也没有解决方案,但我认为是相关的:

我还确保安装了libpng(通过brew)。 谢谢,

我随后发现了另一个可以修复的错误: 首先,我检查了路径中的内容:

macair93278:~ r8t$ echo $DYLD_LIBRARY_PATH

(empty)
接下来找到我需要的文件(libpng15.15.dylib):

现在,我将底部三个附加到路径并检查路径:

macair93278:~ r8t$ echo $DYLD_LIBRARY_PATH  
/usr/X11/lib/libpng15.15.dylib:/Users/r8t/anaconda/pkgs/libpng-1.5.13-1/lib/libpng15.15.dylib:/Users/r8t/anaconda/lib/libpng15.15.dylib
好的,现在测试

macair93278:~ r8t$ ipython

In [1]: import matplotlib

In [2]: from matplotlib import pyplot
…(bunch of output)
ImportError: dlopen(/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: libpng15.15.dylib
Referenced from: /Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
Reason: no suitable image found. Did find:
/usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20
/Users/r8t/anaconda/pkgs/libpng-1.5.13-1/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20
/Users/r8t/anaconda/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20
一个不同的错误!进步! 现在,我运行了brew链接,然后取消链接并没有修复它,但它指出了一个事实,即pyplot正在usr/local/lib中查找libpng15.15.dylib,但它们不在那里:

macair93278:~ r8t$ cd ../usr/local/lib
macair93278:lib r8t$ ls *png*
libpng.a libpng16.16.dylib libpng16.dylib
libpng.dylib libpng16.a
把它们复制到那里:

macair93278:~ r8t$ cp ../anaconda/lib/*png* /usr/local/lib
macair93278:~ r8t$ cd /usr/local/lib
测试:

In [1]: import matplotlib 

In [2]: from matplotlib import pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
    from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.
[1]中的
:导入matplotlib
在[2]中:从matplotlib导入pyplot
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/Users/r8t/anaconda/lib/python2.7/site packages/matplotlib/pyplot.py”,第109行,在
_后端模块、新图形管理器、绘图(如果交互式),显示=pylab\u设置()
pylab_设置中的文件“/Users/r8t/anaconda/lib/python2.7/site packages/matplotlib/backends/_init__.py”,第32行
全局变量(),局部变量(),[backend_name],0)
文件“/Users/r8t/anaconda/lib/python2.7/site packages/matplotlib/backends/backend_macosx.py”,第24行,在
从matplotlib.backends导入_macosx
RuntimeError:Python未作为框架安装。如果Python未作为框架安装,Mac OS X后端将无法正常工作。有关在Mac OS X上安装Python作为框架的更多信息,请参阅Python文档。请重新安装Python作为框架,或者尝试其他后端。
我们已经将问题简化为一个:

(很抱歉,我还不能发表评论..所以这里有一个新帖子)

我在安装另一个库(Spyner)时遇到了相同的问题:
dlopen(…)库未加载libpng15.15.dylib

我尝试了与@travelingbones的答案类似的方法,只想为未来的读者添加一些注释:

  • DYLD_库_路径应包含目录,而不是文件。例如:
  • export DYLD\u LIBRARY\u PATH=/Users/xxx/anaconda/lib:$DYLD\u LIBRARY\u PATH

    不是

    export DYLD\u LIBRARY\u PATH=/Users/xxx/anaconda/lib/libpng15.15.dylib:$DYLD\u LIBRARY\u PATH

    错误
    /usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib:stat()因错误的DYLD_LIBRARY_路径而失败,因为文件路径
    /usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib
    不存在(请注意文件路径中的双
    libpng15.15.dylib

  • 设置新的DYLD_库路径后,我发现matplotlib被弄乱,出现以下错误:
  • importorror:dlopen(/Users/shengao/anaconda/lib/python2.7/site-packages/matplotlib/backends//\u macosx.so,2):未找到符号:\u cg\u jpeg\u重新同步\u至\u重新启动
    引用自:/System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
    在/System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO中需要:/Users/shenggao/anaconda/lib/libjpeg.8.dylib
    
  • 为了解决这个问题,我将DYLD_LIBRARY_PATH更改回旧值(即空),并将libpng路径添加到DYLD_FALLBACK_LIBRARY_PATH 像这样:
  • export DYLD\u FALLBACK\u LIBRARY\u PATH=/Users/shenggao/anaconda/lib:$DYLD\u FALLBACK\u LIBRARY\u PATH


    最后,matplotlib和我的新库工作得非常出色

    我还尝试通过pip卸载matplot库,然后brew重新安装libpng和freetype,然后pip安装matplot库,我得到了相同的错误。。。啊,酷!谢谢分享
    In [1]: import matplotlib 
    
    In [2]: from matplotlib import pyplot
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 109, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
      File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
        globals(),locals(),[backend_name],0)
      File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
        from matplotlib.backends import _macosx
    RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.