Error importing ft2font from matplotlib (python, macosx)

I installed matplotlib to use baseemap today, when I had to install a lot of things to make it work. After installing matplotlib and the import option, I installed the basemap, but I cannot import the basemap due to this error:

from mpl_toolkits.basemap import Basemap

Traceback (last last call): File ", line 1, to File" / usr / local / Cellar / python / 2.7.2 / lib / python2.7 / site-packages / mpl_toolkits / basemap / init .py ", line 36 , from matplotlib.collections import LineCollection File "/ usr / local / Cellar / python / 2.7.2 / lib / python2.7 / site-packages / matplotlib / collections.py", line 22, into 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, from lines import Line2D file" / usr / local / Cellar / python / 2.7.2 / lib / python2 .7 / site-packages / matplotlib / lines.py ", line 23, from from matplot lib.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 Link from: /usr/local/Cellar/python/2.7. 2 / lib / python2.7 / site-packages / matplotlib / ft2font.so Expected in: dynamic search

So, when I tried to import ft2font in python using:

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 am using Mac OSX 10.6 and python 2.7.2 installed by homebrew.

+7
source share
3 answers

I ran into the same problem. Even after running make.osx he still complained about _FT_Attach_File to undefined when I imported ft2font from matplotlib. This is how I figured out the problem. Hope this helps someone else.

Running otool -L ft2font.so gave:

  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 lack of mention of libfreetype! How should ft2font.so find a character if it is not associated with it?

My next step was to capture the commands used during build:

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

The search resulted in a command that was used to compile the corrupted python module. I changed the value of the output file to 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 created for an unsupported file format that is not architecture related (x86_64)

Bingo! Problem found. I know that I have both macports and homebrew installed. Apparently, one of them has a version of libfreetype in /opt/local/lib that is not compiled for the 64-bit version.

I restarted the command with the removal of "-L /opt/local/lib" , which worked without warning. Copying the resulting ft2font.so into my existing matplotlib installation now allows me to successfully import ft2font from matplotlib.

+6
source

In my case, it was an architecture problem - I had the 64-bit version of freetype installed (which matplotlib was happy to compile), but when I launched the 32-bit version of python, I got this error. A simple solution is to remove everything (freetype, matplotlib), and then install both 32 and 64-bit versions using homebrew and -universal flag:

 brew install freetype --universal 

Notice I also had to do this for libpng ( brew install libpng --universal ). Not all home recipes support a universal flag, but it is a huge help to those who do it. (You can see the formula parameters using brew info <FORMULA> ).

In addition, compiling using make.osx Makefile combined with homebrew was a complete failure; in my experience, I would recommend one or the other.

+5
source

Ok, I figured it out.

I reinstalled matplotlib from the source from github (https://github.com/matplotlib/) and then (instead of the usual python setup.py installation) I ran make.osx described in README.OSX:

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

And now everything is working correctly.

+4
source

All Articles