我正在尝试为Python安装matplotlib库。安装没问题但我在Python中导入pylab(例如导入pylab为p)时出现以下错误。
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mathtext.py", line 61, 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): Symbol not found: _png_set_longjmp_fn
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
Expected in: flat namespace in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
Google搜索表明链接错误(不查找“_png_set_longjmp_fn”)与png库的32/64位编译问题有关。
我尝试在库中基于README.osx文件重新安装matplotlib,但它没有修复。我找到的其他方法没有解决它。另外,我检查了库是以32位还是64位编译的。相关二进制文件支持两种(通用二进制文件)如下。
>file /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so (for architecture i386): Mach-O bundle i386
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_png.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
>file /Library/Frameworks/libpng.framework/Versions/Current/libpng
/Library/Frameworks/libpng.framework/Versions/Current/libpng: Mach-O universal binary with 2 architectures
/Library/Frameworks/libpng.framework/Versions/Current/libpng (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/Library/Frameworks/libpng.framework/Versions/Current/libpng (for architecture i386): Mach-O dynamically linked shared library i386
我的OS X版本是Lion 10.7.4。你对这个问题有什么想法吗?感谢!!!
答案 0 :(得分:2)
前几天,当我从matplotlib import pyplot
做的时候,我和你的问题一样。经过五个小时的撞击我的头后,这个解决方案对我有用(来自practicalcomputing.org
我有这组命令来设置simlinks:
sudo mkdir -p /usr/local/include
sudo ln -s /usr/X11/include/freetype2/freetype /usr/local/include/freetype
sudo ln -s /usr/X11/include/ft2build.h /usr/local/include/ft2build.h
sudo ln -s /usr/X11/include/png.h /usr/local/include/png.h
sudo ln -s /usr/X11/include/pngconf.h /usr/local/include/pngconf.h
sudo ln -s /usr/X11/include/pnglibconf.h /usr/local/include/pnglibconf.h
sudo mkdir -p /usr/local/lib
sudo ln -s /usr/X11/lib/libfreetype.dylib /usr/local/lib/libfreetype.dylib
sudo ln -s /usr/X11/lib/libpng.dylib /usr/local/lib/libpng.dylib
它并没有完全解决你的所有问题,但它解决了我的pkg-config问题(以及其他问题)。也许类似的链接有助于QT。