Building matplotlib on OS X

I've had several problems with building on OS X in the past, and was just notified that a bug I opened about it has closed. Eric Firing suggested that I re-open the bug if it is still a problem. It is still a problem, but I can't seem to figure out how to re-open my bug report, so I'll report it again here with an update on the procedures I followed.

First, I downloaded a fresh copy of matplotlib source:

svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib

Then, following the instructions I found in README.osx:
PREFIX=/Users/mhearne/build make -f make.osx fetch deps mpl_install

I then moved my current matplotlib (one from Enthought) aside:
cd /Library/Frameworks/EPD64.framework/Versions/Current/lib/python2.6/site-packages
sudo mv matplotlib matplotlib.old

I then used setup.py to install matplotlib:
sudo /Library/Frameworks/EPD64.framework/Versions/Current/bin/python setup.py install

Then I tried to import ft2font from the ipython command line:
from matplotlib import ft2font

and got the following error:

···

---------------------------------------------------------------------------
ImportError Traceback (most recent call last)

/Users/mhearne/build/matplotlib/<ipython console> in <module>()

ImportError: dlopen(/Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so, 2): Symbol not found: _FT_Attach_File
  Referenced from: /Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so
  Expected in: flat namespace
in /Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so

I've had several problems with building on OS X in the past, and was just notified that a bug I opened about it has closed. Eric Firing suggested that I re-open the bug if it is still a problem. It is still a problem, but I can't seem to figure out how to re-open my bug report, so I'll report it again here with an update on the procedures I followed.

First, I downloaded a fresh copy of matplotlib source:

svn co matplotlib download | SourceForge.net matplotlib

Then, following the instructions I found in README.osx:
PREFIX=/Users/mhearne/build make -f make.osx fetch deps mpl_install

I then moved my current matplotlib (one from Enthought) aside:
cd /Library/Frameworks/EPD64.framework/Versions/Current/lib/python2.6/site-packages
sudo mv matplotlib matplotlib.old

I then used setup.py to install matplotlib:
sudo /Library/Frameworks/EPD64.framework/Versions/Current/bin/python setup.py install

You do not want to do this last step. The mpl_install in the make
command will handle the install. This last step may be building
against different libs, which is probably why you are seeing the
ft2font import link problem.

Note that the install will be put into
$PREFIX/lib/python.6/site-packages so the PREFIX should be your
installation target, not your build target. Ie, it looks like you are
not setting the PREFIX according to the intent.

I suggest something like

  > sudo PREFIX=/Library/Frameworks/EPD64.framework/Versions/Current/
make -f deps mpl_install

for your current file hierarchy. Alternatively, you can do

  > PREFIX=/Users/mhearne/build make -f make binaries

and then use the binary installers that are built to do the site wide install.

JDH

···

On Mon, Jun 7, 2010 at 10:26 AM, Michael Hearne <mhearne@...751...> wrote:

John - I followed your advice, and tried the build/install step again after downloading a completely fresh svn copy of the source:

svn co matplotlib download | SourceForge.net matplotlib
cd matplotlib
sudo PREFIX=/Library/Frameworks/EPD64.framework/Versions/Current/ make -f make.osx fetch deps mpl_install

It successfully compiled and installed matplotlib in my site-packages directory. However, I still see this in ipython:

···

from matplotlib import ft2font

---------------------------------------------------------------------------
ImportError Traceback (most recent call last)

/Users/mhearne/<ipython console> in <module>()

ImportError: dlopen(/Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so, 2): Symbol not found: _FT_Attach_File
  Referenced from: /Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so
  Expected in: flat namespace
in /Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so

Am I missing some other step?

Thanks,

Mike
On Jun 7, 2010, at 9:52 AM, John Hunter wrote:

On Mon, Jun 7, 2010 at 10:26 AM, Michael Hearne <mhearne@...751...> wrote:

I've had several problems with building on OS X in the past, and was just notified that a bug I opened about it has closed. Eric Firing suggested that I re-open the bug if it is still a problem. It is still a problem, but I can't seem to figure out how to re-open my bug report, so I'll report it again here with an update on the procedures I followed.

First, I downloaded a fresh copy of matplotlib source:

svn co matplotlib download | SourceForge.net matplotlib

Then, following the instructions I found in README.osx:
PREFIX=/Users/mhearne/build make -f make.osx fetch deps mpl_install

I then moved my current matplotlib (one from Enthought) aside:
cd /Library/Frameworks/EPD64.framework/Versions/Current/lib/python2.6/site-packages
sudo mv matplotlib matplotlib.old

I then used setup.py to install matplotlib:
sudo /Library/Frameworks/EPD64.framework/Versions/Current/bin/python setup.py install

You do not want to do this last step. The mpl_install in the make
command will handle the install. This last step may be building
against different libs, which is probably why you are seeing the
ft2font import link problem.

Note that the install will be put into
$PREFIX/lib/python.6/site-packages so the PREFIX should be your
installation target, not your build target. Ie, it looks like you are
not setting the PREFIX according to the intent.

I suggest something like

sudo PREFIX=/Library/Frameworks/EPD64.framework/Versions/Current/

make -f deps mpl_install

for your current file hierarchy. Alternatively, you can do

PREFIX=/Users/mhearne/build make -f make binaries

and then use the binary installers that are built to do the site wide install.

JDH

John - I followed your advice, and tried the build/install step again after downloading a completely fresh svn copy of the source:

svn co matplotlib download | SourceForge.net matplotlib
cd matplotlib
sudo PREFIX=/Library/Frameworks/EPD64.framework/Versions/Current/ make -f make.osx fetch deps mpl_install

It successfully compiled and installed matplotlib in my site-packages directory. However, I still see this in ipython:

from matplotlib import ft2font

---------------------------------------------------------------------------
ImportError Traceback (most recent call last)

/Users/mhearne/<ipython console> in <module>()

ImportError: dlopen(/Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so, 2): Symbol not found: _FT_Attach_File
Referenced from: /Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so
Expected in: flat namespace
in /Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages/matplotlib/ft2font.so

Am I missing some other step?

One possibility is that the path from the traceback

  /Library/Frameworks/EPD64.framework/Versions/6.0.0/lib/python2.6/site-packages

is not the same as your PREFIX
"PREFIX=/Library/Frameworks/EPD64.framework/Versions/Current/"

unless "Current" is a symlink to 6.0.0 which it very well may be. Can
you confirm? If you are getting different versions, you'll need to
set your PYTHONPATH.

Alternatively, we may need to set your LD_LIBRARY_PATH or similar to
find the libs we built. They should be in $PREFIX/lib. You can use
otool to see what the linker is finding in your current environment

  > otool -L /Library/Frameworks/EPD64.framework/Versions/Current/lib/python2.6/site-packages/matplotlib/ft2font.so

There may be another way -- you can set your prefix to something like

  PREFIX=~/tmpbuild

and then build as before but do 'make binaries' rather than 'make
mpl_install'. Then use the binary installer to do the system install.
This may get you a build with the support libs statically linked in,
though I am not sure about this. Sorry this is such a pain -- I keep
trying to make a build script that works for people but it obviously
isn't there yet.

JDH

···

On Mon, Jun 7, 2010 at 4:13 PM, Michael Hearne <mhearne@...751...> wrote:

Hi Michael,

may it be that you used different compilers for compiling your
FreeType2 and your matplotlib? [CC=gcc-4.2] It's nearly impossible
to tell afterwards from the libraries.

I was able to compile matplotlib (not the svn though) on OS X Snow
Leopard /without/ using the make.osx script. One has to apply some
changes, but not large ones.

John, I have the slight impression that you constantly try to ignore
me, can you give a good reason, then I will be satisfied. Fixing the
_png.cpp issue for libpng 1.4 would be a good start to make matplotlib
compilable without the effort of make.osx.

I want to add that I'm not an expert and used just standard
approaches. But they worked (for me). Especially I have way to
little knowledge of the implications of 64bit.

Best,
Friedrich

Sorry, I wasn't intentionally ignoring you. I don't have as much time
as I'd like on the mpl mailing list so I sometimes dart in and out.
If there is some thread or two or three where you would like me to
comment or have some patches that need attention, please point me to
them.

Frequently, threads and contributions get left behind. Usually, the
slight is not intentional but just due to bandwidth constraints. It
happens enough that we have a FAQ :slight_smile:

  http://matplotlib.sourceforge.net/faq/howto_faq.html#contributing-howto

JDH

···

On Tue, Jun 8, 2010 at 2:49 PM, Friedrich Romstedt <friedrichromstedt@...149...> wrote:

Hi Michael,

may it be that you used different compilers for compiling your
FreeType2 and your matplotlib? [CC=gcc-4.2] It's nearly impossible
to tell afterwards from the libraries.

I was able to compile matplotlib (not the svn though) on OS X Snow
Leopard /without/ using the make.osx script. One has to apply some
changes, but not large ones.

John, I have the slight impression that you constantly try to ignore
me, can you give a good reason, then I will be satisfied. Fixing the
_png.cpp issue for libpng 1.4 would be a good start to make matplotlib
compilable without the effort of make.osx.