Snow Leopard and lxml

As many of you might already know, I've been dealing a lot with XML and python recently. I also recently upgraded to Mac OS 10.6 Snow Leopard. To my surprise, after the upgrade I noticed that I was now being pushed from python 2.5 to python 2.6. At first I was a little concerned since everything I had been doing was in 2.5, and all of our servers are running 2.5, but I soon found that I could continue to build for 2.5 and upload my eggs, so I welcomed the change.

After a while, I became aware that subversion was also upgraded. Building pysvn again proved to be a difficult task. I upgraded from python 2.5.1 to python 2.5.2 in order to try to also install the development libraries required to build pysvn from source. I had many issues there and then decided to move on and just install subversion 1.6.1 and the python 2.6 egg from the pysvn website.

I then discovered that lxml wasn't installed properly, and every time I tried to install the egg it told me that lxml was a pre-requisite of lxml... a bit of a confusing error message, but basically the change came about because 10.6 builds for 64 bit by default. Eventually, after attempting to build lxml for quite a while, I discovered the issue was that it wasn't working with gcc-4.2, the default compiler. If you get an error like this:

/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
lipo: can't figure out the architecture type of: /var/folders/....
Then you have to do two things.

First of all, make sure you install the new XCode including the XCode 10.4 SDK (an optional install that is unchecked by default). For some reason most of the python modules I've found seem to rely on the 10.4 SDK and they even back-port the install for 10.3.

Secondly, you have to change your default compiler from gcc 4.2 to gcc 4.0. This can be done by removing the symlink file in /usr/bin/gcc and re-linking that to gcc-4.0. This can be done by doing:

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.0 /usr/bin/gcc

After all that is done, you should be able to download lxml and build it using the standard Mac build command:
python install --static-deps


Pau RuĂ© said…
I had the same problem building matplotlib and this trick worked for me also.

Chris Perkins said…
Thanks for this! It helped me get pyamf working.
David said…
Switching from gcc-4.2 to gcc-4.0 still fails, but now with "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
Luke Sneeringer said…
This consistently bombs out for me as well. I get an error:

lipo: can't figure out the architecture type of: /var/tmp//ccbMtETR.out

and then make exits with code 2. Python gives a long traceback but the fail is in make.