从 matplotlib 导入错误 ft2font(python、macosx)
我今天正在安装 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 导入 LineCollection 文件“/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/collections.py”,第 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 导入 ft2font ImportError:dlopen(/usr/local/Cellar/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 和由 homebrew 安装的 python 2.7.2。
I was installing matplotlib to use basemap today when I had to install a lot of stuff to make it work. After installing matplotlib and be able to import it I installed basemap but I can't import basemap because of this error:
from mpl_toolkits.basemap import Basemap
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/mpl_toolkits/basemap/init.py", line 36, in
from matplotlib.collections import LineCollection
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/collections.py", line 22, in
import matplotlib.backend_bases as backend_bases
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 38, in
import matplotlib.widgets as widgets
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/widgets.py", line 16, in
from lines import Line2D
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/lines.py", line 23, in
from matplotlib.font_manager import FontProperties
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib/font_manager.py", line 52, in
from matplotlib import ft2font
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
So when I tried to import ft2font in python by:
from matplotlib import ft2font
I got this error:
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
Any idea what to do?
I'm using Mac OSX 10.6 and python 2.7.2 installed by homebrew.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题。即使在运行
make.osx
后,当我从 matplotlib 导入ft2font
时,它仍然抱怨_FT_Attach_File
未定义。这是我找出问题的方法。希望它能对其他人有所帮助。运行
otool -L ft2font.so
得到:请注意,没有提及 libfreetype!如果没有链接到该符号,
ft2font.so
应该如何定位该符号?我的下一步是捕获构建期间使用的命令:
搜索此命令产生用于编译有问题的 python 模块的命令。我将本地目录中的输出文件的值更改为 1 并运行它:
宾果!发现问题了。我知道我已经安装了 macports 和 homebrew。显然,其中一个在
/opt/local/lib
中有一个libfreetype
版本,该版本不是为 64 位编译的。我重新运行了该命令,删除了“-L /opt/local/lib”,该命令在没有警告的情况下工作。现在,将生成的 ft2font.so 复制到我现有的 matplotlib 安装中,可以从 matplotlib 成功导入 ft2font。
I ran into the same issue. Even after running
make.osx
, it still complained about_FT_Attach_File
being undefined when I importedft2font
from matplotlib. Here's how I tracked down the problem. Hopefully, it will help someone else.Running
otool -L ft2font.so
yielded:Note the absence of any mention of libfreetype! How is
ft2font.so
supposed to locate the symbol if it isn't linked against it?My next step was to capture the commands used during the build:
Searching this yielded the command that was used to compile the offending python module. I changed the value of the output file to be one in my local directory and ran it:
Bingo! Problem found. I know I have both macports and homebrew installed. Apparently, one of them has a version of
libfreetype
in/opt/local/lib
that isn't compiled for 64-bit.I reran the command with
"-L /opt/local/lib"
removed which worked without a warning. Copying the resultingft2font.so
into my existing matplotlib installation now allows me to successfully importft2font
from matplotlib.就我而言,这是一个架构问题 - 我安装了 64 位版本的 freetype(matplotlib 很高兴地对其进行了编译),但是当我在 32 位版本的 python 中运行时,我收到了该错误。简单的解决方案是卸载所有内容(freetype、matplotlib),然后使用 homebrew 和 --universal 标志安装 32 位和 64 位版本:
注意,我也必须对 libpng 执行此操作(
brew install libpng --通用
)。并非所有自制食谱都支持通用标志,但这对于支持通用标志的食谱来说是一个巨大的帮助。 (您可以使用brew info
查看公式的选项)。此外,使用 make.osx Makefile 与自制程序一起进行编译是完全失败的;根据我的经验,我会推荐其中之一。
In my case, this was an architecture problem - I had a 64bit version of freetype installed (that matplotlib happily compiled against) but when I ran in a 32bit version of python I got that error. The easy solution is to uninstall everything (freetype, matplotlib), and then install both the 32 and 64bit versions using homebrew and the --universal flag:
Note, I also had to do this for libpng as well (
brew install libpng --universal
). Not all homebrew recipes support the universal flag, but it's a huge help for the ones that do. (You can see a formula's options withbrew info <FORMULA>
).Also, compiling using the make.osx Makefile in conjunction with homebrew was a total failure; in my experience I'd recommend one or the other.
好吧,我明白了。
我从 github (https://github.com/matplotlib/) 的源代码重新安装了 matplotlib,然后(而不是普通的 python setup.py install)我运行了 README.OSX 中描述的 make.osx:
现在一切正常。
Okay, I figured it out.
I reinstalled matplotlib from source from github (https://github.com/matplotlib/) and then (instead of ordinary python setup.py install) I ran make.osx described in README.OSX:
And everything works properly now.