Tim found a secret in Macports that solves my problem building PIL for Python2.5 on Snow Leopard (SL).
It turns out that by default (at least on SL) Macports only builds a x86_64 binaries. Running the file command shows it’s only one architecture, something like:
[berto@bolt][524]$ file /opt/local/lib/libpcrecpp.dylib /opt/local/lib/libpcrecpp.dylib: Mach-O 64-bit dynamically linked shared library x86_64
SL’s Python2.5 isn’t even built for x86_64, which is the reason PIL blows up in Python2.5:
[berto@bolt][523]$ file /usr/bin/python2.5 /usr/bin/python2.5: Mach-O universal binary with 2 architectures /usr/bin/python2.5 (for architecture i386): Mach-O executable i386 /usr/bin/python2.5 (for architecture ppc7400): Mach-O executable ppc
The solution is to tell Macports to build universal binaries. This can be done by adding +universal to the command line, for example:
sudo port install jpeg +universal
A more general solution is to add this “variant” to the Macports config. Simply add +universal to the file /opt/local/etc/macports/variants.conf. The file is read-only, even for root, so make sure to force-write the file (:wq! in vi).
And if you want to rebuild everything universal, sledgehammer approach:
sudo port upgrade --force installed
More info from Tim:
Note that the architectures it picks might not be what you want. On Leopard Intel it appears to do i386 x86_64. If you want ppc, set ‘universal_archs ppc i386 ppc64 x86_64′ (note NO EQUALS).
in /opt/local/etc/macports/macports.conf
Rebuilding all is the command you wanted, or for just the specific ones
needed, ‘sudo port upgrade –enforce-variants curl’ should do it to add
+universal (it won’t rebuild when you change universal_archs though).
Once Macports is universal, rebuilding and installing PIL works like a charm!
2009/12/19 at 1:35 am |
This was very handy for preparing my 10.6 install for building wine-devel with macports. Thanks!
2010/03/27 at 5:16 am |
[...] variants file. For more indepth and usful info about this see the page where I got the answers: http://rcaguilar.wordpress.com/2009/11/04/universal-binaries-in-macports/ chris's [...]
2010/06/29 at 10:22 am |
Thank you for the great article. I found it very helpful in getting my system to compile and work correctly. I find the ports documentation a little sparse and was having a tiny bit of trouble following all of the steps above. I created a small step by step writeup to share: http://thejacobtaylor.blogspot.com/2010/06/getting-pil-to-work-well-on-snow.html
Cheers,
Jacob
2010/07/16 at 1:46 pm |
Good article on this, but it may be easier for some users to simply tell the setup.py script to build only for a specified architecture. For instance, I did an ‘in place’ build on my intel Mac by doing the following (caution: this assumes you have already installed the dependent libraries for jpeg, png, etc…):
$MacHD:Imaging-1.1.7 asw$ ARCHFLAGS=”-arch i386″ python setup.py build_ext -i
This worked like a charm on 10.5.8 with Python 2.6, libjpeg 6a, libpng 1.4.1, and Freetype 2.3.9 (all installed in /usr/local/lib). Clearly this won’t work if your libxml2.2.dylib is of the wrong architecture, but since that’s never supposed to happen with a correct Macport install it really shouldn’t matter.
2013/04/11 at 7:16 am |
sudo port upgrade –enforce-variants active +universal
possibly?
2013/04/11 at 11:32 am |
Thanks for the tip!