Can't import pyplot, symbol not found error instead

I just installed matplotlib-1.0.0 on my system (Snow Leopard, python 2.7), but somehow when I try to import pyplot i get the error below.

For reference, I installed matplotlib from source. Prior to that I installed libpng-1.4.4 and freetype-2.4.2 the usual way (./configure, make, make install) plus I installed pkgcong as well. After getting the error I tried the tips Friedrich R gave in this thread (http://old.nabble.com/Symbol-not-found-td28994434.html) too, but I still get the error.

From a few google attempts it seems that it is an issue of dynamic vs static linking. I can’t say that I know what that is, but I’d be very interested in knowing whether I can do anything from my side to sort things out.

Here is the error:

import matplotlib.pyplot as plt

Traceback (most recent call last):

File “<pyshell#2>”, line 1, in

import matplotlib.pyplot as plt

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py”, line 23, in

from matplotlib.figure import Figure, figaspect

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py”, line 18, in

from axes import Axes, SubplotBase, subplot_class_factory

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py”, line 14, in

import matplotlib.axis as maxis

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py”, line 10, in

import matplotlib.font_manager as font_manager

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/font_manager.py”, line 52, in

from matplotlib import ft2font

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/ft2font.so, 2): Symbol not found: _FT_Attach_File

Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/ft2font.so

Expected in: dynamic lookup

Yaaa, this was some time ago, I guess you did the following:

* export CC=gcc-4.2
* export MACOSX_DEPLOYMENT_TARGET=....
* maybe also modifying the setupext.py

I must say, that Python distutils (or distribute, whatever you use)
overrides the CC environment variable with the gcc version Python was
compiled with. If you use python.org Python, this will be gcc-4.0.
Could be that this is your issue: You compiled freetype with gcc-4.2
and Python uses gcc-4.0 for compiling matplotlib. Then the matplotlib
libraries cannot load the gcc-4.2 compiled ones, because they are "too
new". Encountered this several times on my own computer.

Notice that the setupext.py instructions are still valid. The
_png.cpp instructions are obsolete for recent versions of matplotlib,
you can use libpng-1.4 right away.

First, I'll wait for your response if you use python.org Python, and
then we see what to do next. Don't want to bombard you with
non-applicable recommendations.

Concerning your message:

2010/10/3 Åke Kullenberg <ake.kullenberg@...287...>:

I just installed matplotlib-1.0.0 on my system (Snow Leopard, python 2.7),
but somehow when I try to import pyplot i get the error below.
For reference, I installed matplotlib from source. Prior to that I installed
libpng-1.4.4 and freetype-2.4.2 the usual way (./configure, make, make
install) plus I installed pkgcong as well. After getting the error I tried
the tips Friedrich R gave in this thread
(http://old.nabble.com/Symbol-not-found-td28994434.html) too, but I still
get the error.

Notice, I'm using Python 2.6, I hope this won't be an issue. Using
Snow Leopard as well.

From a few google attempts it seems that it is an issue of dynamic vs static
linking. I can't say that I know what that is, but I'd be very interested in
knowing whether I can do anything from my side to sort things out.

Hmm, here maybe you also ran across what I said, just to add that
afaict make.osx isn't doing static linking, but rather linking against
newly-installed shared libs. The libs are compiled just by the
make.osx script. Got this impression when I had an own look into the
script.

Here is the error:
from matplotlib import ft2font
ImportError:
dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/ft2font.so,
2): Symbol not found: _FT_Attach_File
Referenced from:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/ft2font.so
Expected in: dynamic lookup

Yeah, this looks pretty much like what I said.

Sorry for the confusion with the old threads, I think best will be to
search the matplotlib archive for recent threads, my replies got
better with time, as I sorted out things myself. I really feel I
should write things up for the matplotlib page as far as I came so far
with my investigations ... And please reply back.

If the external libraries you're using change: Do a new build in a
new, freshly untared matplotlib directory or sth like that. I found
that, for some reason, it is necessary to really rebuild the
matplotlib libraries when a shared library they load is changed. It
is not sufficient to just replace the external shared library (like
freetype2) to make it work. My knowledge in linking is not as deep as
that I could explain the guts why this is so, but you have to do it (I
had to at least). Keep in mind that dependency checks do not include
the shared libs matplotlib libraries like ft2font rely on. I can only
guess that it only applies to the gcc-4.0/4.2 issue. Otherwise shared
libs would be nearly useless.

Friedrich

The gcc-4.0/4.2 issue was the key to the problem. I did this and matplotlib got installed without any issue, and I could import pyplot ok.

  • First I set ‘export CC=gcc-4.0’

  • In the same terminal I ran the usual configure/make/make install for libpng and freetype

  • I then rebuilt matplotlib the usual way (python setup.py build, sudo python setup.py install)

Before rebuilding matplotlib I edited setupext.py the ‘darwin’ line in the basedir declaration accordingly:

‘darwin’ : [],

to

‘darwin’ : [’/usr/local’],

I don’t know if that was necessary but I did it anyway.

Thanks for the help Friedrich. I did actually see that matplotlib was compiled with gcc-4.0, but it never occured to me that libpng / freetype should use the same compiler.

···

On Tue, Oct 5, 2010 at 3:46 AM, Friedrich Romstedt <friedrichromstedt@…287…> wrote:

Yaaa, this was some time ago, I guess you did the following:

  • export CC=gcc-4.2

  • export MACOSX_DEPLOYMENT_TARGET=…

  • maybe also modifying the setupext.py

I must say, that Python distutils (or distribute, whatever you use)

overrides the CC environment variable with the gcc version Python was

compiled with. If you use python.org Python, this will be gcc-4.0.

Could be that this is your issue: You compiled freetype with gcc-4.2

and Python uses gcc-4.0 for compiling matplotlib. Then the matplotlib

libraries cannot load the gcc-4.2 compiled ones, because they are "too

new". Encountered this several times on my own computer.

Notice that the setupext.py instructions are still valid. The

_png.cpp instructions are obsolete for recent versions of matplotlib,

you can use libpng-1.4 right away.

First, I’ll wait for your response if you use python.org Python, and

then we see what to do next. Don’t want to bombard you with

non-applicable recommendations.

Concerning your message:

2010/10/3 Åke Kullenberg <ake.kullenberg@…287…>:

I just installed matplotlib-1.0.0 on my system (Snow Leopard, python 2.7),

but somehow when I try to import pyplot i get the error below.

For reference, I installed matplotlib from source. Prior to that I installed

libpng-1.4.4 and freetype-2.4.2 the usual way (./configure, make, make

install) plus I installed pkgcong as well. After getting the error I tried

the tips Friedrich R gave in this thread

(http://old.nabble.com/Symbol-not-found-td28994434.html) too, but I still

get the error.

Notice, I’m using Python 2.6, I hope this won’t be an issue. Using

Snow Leopard as well.

From a few google attempts it seems that it is an issue of dynamic vs static

linking. I can’t say that I know what that is, but I’d be very interested in

knowing whether I can do anything from my side to sort things out.

Hmm, here maybe you also ran across what I said, just to add that

afaict make.osx isn’t doing static linking, but rather linking against

newly-installed shared libs. The libs are compiled just by the

make.osx script. Got this impression when I had an own look into the

script.

Here is the error:
from matplotlib import ft2font

ImportError:

dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/ft2font.so,

2): Symbol not found: _FT_Attach_File

Referenced from:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/ft2font.so

Expected in: dynamic lookup

Yeah, this looks pretty much like what I said.

Sorry for the confusion with the old threads, I think best will be to

search the matplotlib archive for recent threads, my replies got

better with time, as I sorted out things myself. I really feel I

should write things up for the matplotlib page as far as I came so far

with my investigations … And please reply back.

If the external libraries you’re using change: Do a new build in a

new, freshly untared matplotlib directory or sth like that. I found

that, for some reason, it is necessary to really rebuild the

matplotlib libraries when a shared library they load is changed. It

is not sufficient to just replace the external shared library (like

freetype2) to make it work. My knowledge in linking is not as deep as

that I could explain the guts why this is so, but you have to do it (I

had to at least). Keep in mind that dependency checks do not include

the shared libs matplotlib libraries like ft2font rely on. I can only

guess that it only applies to the gcc-4.0/4.2 issue. Otherwise shared

libs would be nearly useless.

Friedrich