从 matplotlib 导入错误 ft2font(python、macosx)

发布于 2024-12-05 15:34:01 字数 2068 浏览 1 评论 0原文

我今天正在安装 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生再见 2024-12-12 15:34:01

我遇到了同样的问题。即使在运行 make.osx 后,当我从 matplotlib 导入 ft2font 时,它仍然抱怨 _FT_Attach_File 未定义。这是我找出问题的方法。希望它能对其他人有所帮助。

运行 otool -L ft2font.so 得到:

    ft2font.so:
/Users/jbenuck/mpl_build/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

请注意,没有提及 libfreetype!如果没有链接到该符号,ft2font.so 应该如何定位该符号?

我的下一步是捕获构建期间使用的命令:

    make -f make.osx PREFIX=/usr/local clean fetch deps mpl_build > output.txt

搜索此命令产生用于编译有问题的 python 模块的命令。我将本地目录中的输出文件的值更改为 1 并运行它:

/Developer/usr/bin/llvm-g++-4.2 -bundle -未定义的dynamic_lookup -isysroot / -L/opt/local/lib -arch i386 -arch x86_64 -L/usr/local/lib -syslibroot,/Developer /SDKs/MacOSX10.7.sdk -arch i386 -arch x86_64 -I/usr/local/include -I/usr/local/include/freetype2 -isysroot /Developer/SDKs/MacOSX10.7.sdk build/temp.macosx-10.7-x86_64-2.7/src/ft2font.o build/temp.macosx-10.7-x86_64-2.7 /src/mplutils.o build/temp.macosx-10.7-x86_64-2.7/CXX/cxx_extensions.o build/temp.macosx-10.7-x86_64-2.7/CXX/cxxsupport.o build/temp.macosx-10.7-x86_64-2.7/CXX/IndirectPythonInterface。哦build/temp.macosx-10.7-x86_64-2.7/CXX/cxxextensions.o -L/usr/local/lib -L/usr/local/lib -L/usr/lib -L/usr/X11/lib -lfreetype - lz -lstdc++ -lm -o ft2font.so

ld:警告:忽略文件/opt/local/lib/libfreetype.dylib,该文件是为不受支持的文件格式构建的,该格式不是正在链接的体系结构(x86_64)

宾果!发现问题了。我知道我已经安装了 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 imported ft2font from matplotlib. Here's how I tracked down the problem. Hopefully, it will help someone else.

Running otool -L ft2font.so yielded:

    ft2font.so:
/Users/jbenuck/mpl_build/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

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:

    make -f make.osx PREFIX=/usr/local clean fetch deps mpl_build > output.txt

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:

/Developer/usr/bin/llvm-g++-4.2 -bundle -undefined dynamic_lookup -isysroot / -L/opt/local/lib -arch i386 -arch x86_64 -L/usr/local/lib -syslibroot,/Developer/SDKs/MacOSX10.7.sdk -arch i386 -arch x86_64 -I/usr/local/include -I/usr/local/include/freetype2 -isysroot /Developer/SDKs/MacOSX10.7.sdk build/temp.macosx-10.7-x86_64-2.7/src/ft2font.o build/temp.macosx-10.7-x86_64-2.7/src/mplutils.o build/temp.macosx-10.7-x86_64-2.7/CXX/cxx_extensions.o build/temp.macosx-10.7-x86_64-2.7/CXX/cxxsupport.o build/temp.macosx-10.7-x86_64-2.7/CXX/IndirectPythonInterface.o build/temp.macosx-10.7-x86_64-2.7/CXX/cxxextensions.o -L/usr/local/lib -L/usr/local/lib -L/usr/lib -L/usr/X11/lib -lfreetype -lz -lstdc++ -lm -o ft2font.so

ld: warning: ignoring file /opt/local/lib/libfreetype.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64)

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 resulting ft2font.so into my existing matplotlib installation now allows me to successfully import ft2font from matplotlib.

情丝乱 2024-12-12 15:34:01

就我而言,这是一个架构问题 - 我安装了 64 位版本的 freetype(matplotlib 很高兴地对其进行了编译),但是当我在 32 位版本的 python 中运行时,我收到了该错误。简单的解决方案是卸载所有内容(freetype、matplotlib),然后使用 homebrew 和 --universal 标志安装 32 位和 64 位版本:

brew install freetype --universal

注意,我也必须对 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:

brew install freetype --universal

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 with brew 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.

掌心的温暖 2024-12-12 15:34:01

好吧,我明白了。

我从 github (https://github.com/matplotlib/) 的源代码重新安装了 matplotlib,然后(而不是普通的 python setup.py install)我运行了 README.OSX 中描述的 make.osx:

make -f make.osx PREFIX=/devjunk PYVERSION=2.7 \
  clean fetch deps mpl_install_std

现在一切正常。

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:

make -f make.osx PREFIX=/devjunk PYVERSION=2.7 \
  clean fetch deps mpl_install_std

And everything works properly now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文