import matplotlib.pyplot gives ImportError: dlopen(…) Library not loaded libpng15.15.dylib

时间秒杀一切 提交于 2019-12-01 07:04:56

(sorry I can not comment yet.. so here's a new post)

I had the same problem when installing another library (spynner): dlopen(…) Library not loaded libpng15.15.dylib

I tried a similar method to @travelingbones's answer, and just wanted to add some notes for future readers:

  1. DYLD_LIBRARY_PATH should contain directories, not files. E.g.,

export DYLD_LIBRARY_PATH=/Users/xxx/anaconda/lib:$DYLD_LIBRARY_PATH

and not

export DYLD_LIBRARY_PATH=/Users/xxx/anaconda/lib/libpng15.15.dylib:$DYLD_LIBRARY_PATH

The error /usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20 is caused by the wrong DYLD_LIBRARY_PATH, since file path /usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib does not exist (notice the double libpng15.15.dylib in the file path).

  1. After I had set the new DYLD_LIBRARY_PATH, I found my matplotlib was messed up, with the following error:
ImportError: dlopen(/Users/shenggao/anaconda/lib/python2.7/site-packages/matplotlib/backends/_macosx.so, 2): Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /Users/shenggao/anaconda/lib/libjpeg.8.dylib in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
  1. To solve this problem, I changed DYLD_LIBRARY_PATH back to the old value (i.e., empty), and added the libpng path to DYLD_FALLBACK_LIBRARY_PATH like this:

export DYLD_FALLBACK_LIBRARY_PATH=/Users/shenggao/anaconda/lib:$DYLD_FALLBACK_LIBRARY_PATH

Finally matplotlib and my new library worked like a charm!

travelingbones

I followed these directions and got a different error that's fixable: First I checked what's in that path:

macair93278:~ r8t$ echo $DYLD_LIBRARY_PATH

(empty)

Next to locate the file I need (libpng15.15.dylib):

macair93278:~ r8t$ locate libpng15.15.dylib
/Applications/KeePassX.app/Contents/MacOS/libpng15.15.dylib
/Users/r8t/anaconda/lib/libpng15.15.dylib
/Users/r8t/anaconda/pkgs/libpng-1.5.13-1/lib/libpng15.15.dylib
/usr/X11/lib/libpng15.15.dylib

Now I appended the bottom three to the path and checked the path:

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

ok, so now the test,

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

A different error! progress! Now following this page I ran the brew link, then unlink it didn't fix it, but it pointed me to the fact that pyplot is looking for libpng15.15.dylib in usr/local/lib but they aren' there:

macair93278:~ r8t$ cd ../usr/local/lib
macair93278:lib r8t$ ls *png*
libpng.a libpng16.16.dylib libpng16.dylib
libpng.dylib libpng16.a

So copy them in there:

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

The test:

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.

And we've reduced the problem to this (solved) one: problem w/ mac os backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!