2

我正在尝试为 Python 安装 matplotlib 库。安装没问题,但是当我在 Python 中导入 pylab(例如 import pylab as 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。你对这个问题有什么想法吗?谢谢!!!

4

1 回答 1

2

前几天我遇到了和你一样的问题matplotlib import pyplot。在将我的头撞到墙上五个小时后,这个解决方案对我有用(来自实用计算.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 有所帮助。

于 2013-01-02T22:25:16.950 回答