首页 文章

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

提问于
浏览
7

我今天正在安装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 回答

  • 6

    好的,我明白了 .

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

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

    现在一切正常 .

  • 5

    在我的情况下,这是一个架构问题 - 我安装了64位版本的freetype(matplotlib很高兴编译反对)但是当我运行32位版本的python时,我得到了这个错误 . 简单的解决方案是卸载所有内容(freetype,matplotlib),然后使用自制软件和--universal标志安装32位和64位版本:

    brew install freetype --universal
    

    注意,我也必须为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进行编译是完全失败的;根据我的经验,我推荐一个或另一个 .

  • 4

    我遇到了同样的问题 . 即使在运行 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模块的命令 . 我将输出文件的值更改为本地目录中的值并运行它:

    / 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:忽略文件/ opt / local / lib / libfreetype.dylib,文件是为不支持的文件格式构建的,而不是链接的体系结构(x86_64)

    答对了!发现问题 . 我知道我安装了macport和homebrew . 显然,其中一个在 /opt/local/lib 中的 libfreetype 版本没有为64位编译 .

    我重新命令 "-L /opt/local/lib" 删除了没有警告的工作 . 将生成的 ft2font.so 复制到我现有的matplotlib安装中,现在允许我从matplotlib成功导入 ft2font .

相关问题