caveats found installing matplotlib from svn source on python 2.7 in mac os x Leopard

Hi,

First of all, thanks to the matplotlib developers for all the great job. I have just successfully installed matplotlib from source (r8827) in my macbook for python 2.7. However, I found a couple of bumps in the road that I’d like to share:

  1. Dependencies: I initially used make.osx to fetch and build png, freetype and zlib. However, for libpng for some reason either urllib was not fetching the right file or it was corrupted, and when running:
    sudo make -f make.osx fetch deps
    make crashed because of an error in tar when trying to unpack the source (I tried tar myself and it also crashed). I ended up downloading manually the sources and then used make.osx to install each of them individually. Also, at least in the case of libpng, the exact version does not seem to matter, and I ended up upgrading to libpng 1.4.5.

  2. make.osx configuration: in my case I had to change the python version and mac osx targets to 2.7 and 10.5 respectively, and I selected /usr/local as the prefix. Still, I found a problem with the architecture flags that made the linker fail when running:
    sudo make -f make.osx mpl_build
    After struggling a little bit it turned out that the problem was in setup.py itself, which called c++ using the -arch ppc flag. This is probably due to the fact that the OSX package provided by Python.org for Mac OS X below 10.6 (Leopard and below) is a universal binary and therefore python compiles against i386 and ppc architectures. Now, make.osx lets you change the architecture flags in line 11, however the compiler and linker flags do not use the variable defined there, and -arch ppc must be added in both lines 20 and 21.

  3. After building matplotlib, contrary to what is mentioned in a couple of sites, python setup.py install crashed and I had to use make.osx to install matplotlib. One important thing when make.osx is used is that it installs matplotlib in a site-package directory that hangs from the PREFIX directory that has to be defined in make.osx, instead of sniffing the site-package used by the current version of python. Therefore, I had to copy everything into the site-package folder inside of …/Python.framework/Versions/2.7 in order to be able to import it. Alternatively, you can add the alternative site-package path to PYTHONPATH, but it is less tidy, in my opinion.

All in all, a bumpy experience and not too user-friendly, but at least it worked. I include below a copy of the final make.osx that worked for me:

Cheers,

AY

build mpl into a local install dir with

PREFIX=/usr/local
MPLVERSION=1.0rc1
PYVERSION=2.7
PYTHON=python${PYVERSION}
ZLIBVERSION=1.2.3
PNGVERSION=1.4.5
FREETYPEVERSION=2.3.11
MACOSX_DEPLOYMENT_TARGET=10.5
OSX_SDK_VER=10.5
#Next line is useless, see below:
ARCH_FLAGS="-arch i386 -arch ppc"

You shouldn’t need to configure past this point – Actually I did

Commenting 20 and 21 and uncommenting the CFLAGS and LDFLAGS below should also work

#PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
#CFLAGS="${ARCH_FLAGS} -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
#LDFLAGS="${ARCH_FLAGS} -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"

PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-arch i386 -arch ppc -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="-arch i386 -arch ppc -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"

ayg256 wrote:

First of all, thanks to the matplotlib developers for all the great job.
I
have just successfully installed matplotlib from source (r8827) in my
macbook for python 2.7. However, I found a couple of bumps in the road
that
I'd like to share:

...

Cheers,

AY

Dear AY,

Thanks so much for posting your followup. I just went through building
matplotlib 1.0.0 from source on my new iMac and your directions were
invaluable. I did need to make some minor modifications to match the
peculiarities of my setup - for example I am installing it with python 2.6.

PYC FILE ISSUES
After install and the manual copy to /Library/Python/2.6/site-packages
(which is where numpy and scipy get built on this machine), the pyc files
are pointing to /usr/local/lib still, which is something that shows up in
ipython when browsing functions, and in backtraces... apparently this is a
bug in python that got fixed in 2.7. To work around, I just remade the pyc
files. I recompiled them all with compileall.compile_dir. The copying and
pyc compilation had to be done with sudo commands since I didn't have
permissions.

FOURIER DEMO - PROBLEM AND FIX IN "lines.py"
Next I tried my wx-based gui http://wiki.wxpython.org/MatplotlibFourierDemo.
It raised assertions in lines.py, particularly the part where it tries to
access
        path, affine =
self._transformed_path.get_transformed_path_and_affine()
(line 286)
since self._transformed_path is None.
When I fixed that by inserting
        if self._transformed_path is None:
            self._transform_path()
then it ran into problems with
       ind += self.ind_offset
since ind_offset didn't exist.
I fixed that by adding
        if hasattr(self, 'ind_offset'):

Is modifying lines.py the only way to fix this, or should I do something
else in the fourier demo?

Best regards, Happy New Year to all, etc,
- Tom K.

···

--
View this message in context: http://old.nabble.com/caveats-found-installing-matplotlib-from-svn-source-on-python-2.7-in-mac-os-x-Leopard-tp30478244p30575604.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

[...]

FOURIER DEMO - PROBLEM AND FIX IN "lines.py"
Next I tried my wx-based gui http://wiki.wxpython.org/MatplotlibFourierDemo.
It raised assertions in lines.py, particularly the part where it tries to
access
         path, affine =
self._transformed_path.get_transformed_path_and_affine()
(line 286)
since self._transformed_path is None.
When I fixed that by inserting
         if self._transformed_path is None:
             self._transform_path()
then it ran into problems with
        ind += self.ind_offset
since ind_offset didn't exist.
I fixed that by adding
         if hasattr(self, 'ind_offset'):

Is modifying lines.py the only way to fix this, or should I do something
else in the fourier demo?

I suspect this is a problem in 1.0 but not in svn or the new 1.0.1rc. I can't reproduce it using very recent svn.

Eric

···

On 01/02/2011 05:40 PM, Tom K. wrote:

Best regards, Happy New Year to all, etc,
  - Tom K.