我今天正在安装matplotlib以使用底图,因为我必须安装很多东西才能使它工作 . 安装matplotlib并能够导入后我安装了底图但由于此错误导致我无法导入底图:
来自mpl_toolkits.basemap导入底图回溯(最近一次调用最后一次):文件“”,第1行,在文件“/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/mpl_toolkits/ basemap / init.py“,第36行,来自matplotlib.collections import LineCollection File”/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/collections.py“,line 22,在导入matplotlib.backend_bases作为backend_bases文件“/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/backend_bases.py”,第38行,在导入matplotlib.widgets中小部件文件“/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/widgets.py”,第16行,从行导入Line2D文件“/ usr / local / Cellar / python / 2.7.2 / lib / python2.7 / site-packages / matplotlib / lines.py“,第23行,来自matplotlib.font_manager导入FontProperties文件”/usr/local/Cellar/python/2.7.2/lib/ python2.7 / site-packages / matplotlib / font_manager.py“,第52行,来自matplotlib import ft2font ImportError:dlopen(/ usr / local / Ce llar / python / 2.7.2 / lib / python2.7 / site-packages / matplotlib / ft2font.so,2):找不到符号:_FT_Attach_File引用自:/usr/local/Cellar/python/2.7.2/lib/ python2.7 / site-packages / matplotlib / ft2font.so预期:动态查找
所以当我尝试在python中导入ft2font时:
来自matplotlib导入ft2font
我收到了这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/ft2font.so, 2): Symbol not found: _FT_Attach_File
Referenced from: /usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/ft2font.so
Expected in: dynamic lookup
知道该怎么办?我正在使用自制软件安装的Mac OSX 10.6和python 2.7.2 .
3 回答
好的,我明白了 .
我从源代码重新安装matplotlib来自github(https://github.com/matplotlib/),然后(而不是普通的python setup.py安装)我运行了README.OSX中描述的make.osx:
现在一切正常 .
在我的情况下,这是一个架构问题 - 我安装了64位版本的freetype(matplotlib很高兴编译反对)但是当我运行32位版本的python时,我得到了这个错误 . 简单的解决方案是卸载所有内容(freetype,matplotlib),然后使用自制软件和--universal标志安装32位和64位版本:
注意,我也必须为libpng做这个(
brew install libpng --universal
) . 并非所有自制食谱都支持通用标志,但's a huge help for the ones that do. (You can see a formula'选项与brew info <FORMULA>
) .另外,使用make.osx Makefile和homebrew进行编译是完全失败的;根据我的经验,我推荐一个或另一个 .
我遇到了同样的问题 . 即使在运行
make.osx
之后,当我从matplotlib导入ft2font
时,仍然抱怨_FT_Attach_File
未定义 . 这是我如何追踪问题 . 希望它会帮助别人 .运行
otool -L ft2font.so
产生:注意没有提到libfreetype!
ft2font.so
如果没有与之链接,应该如何找到该符号?我的下一步是捕获构建期间使用的命令:
搜索它产生了用于编译有问题的python模块的命令 . 我将输出文件的值更改为本地目录中的值并运行它:
答对了!发现问题 . 我知道我安装了macport和homebrew . 显然,其中一个在
/opt/local/lib
中的libfreetype
版本没有为64位编译 .我重新命令
"-L /opt/local/lib"
删除了没有警告的工作 . 将生成的ft2font.so
复制到我现有的matplotlib安装中,现在允许我从matplotlib成功导入ft2font
.