Today I spent a good long chunk of my day shouting at my computer and trying to install matplotlib, a very handy python library. I finally solved it, so figured it was worth posting about here, in case anyone else has the same problem.
I recently updated my system python to version 2.7, so I've had to go through reinstalling various libraries that I use on a semi-regular basis. Matplotlib is one of these that up until now I've had no call for. However, my experiment project that I'm working on needs some pretty graphs, so I needed to get matplotlib installed.
I tried to install using pip, I tried to install using easy_install, and I tried to install by downloading the source and compiling it. None of these methods worked and I was often getting compiler errors like this:
llvm-g++-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-g++-4.2': execvp: No such file or directory
Which is very annoying. So I spent some time googling, and it seemed that the reason for these errors is that the compiler was trying to build a universal version of some library - a version that would work on both 32 and 64 bit intel macs and older powerpc based macs. However, Apple have now removed all traces of powerpc support from osX and Xcode, so the compiler was failing. There is a way to add ppc support back to Lion, but either I was doing it wrong or those instructions are slightly out of date, because it didn't solve my problem. Now, depending on how I'd tried to fix the problem, it would fail with a lot of errors in compiling "ft2font.cpp". Other times it would be accompanied with "i686-apple-darwin10-gcc-4.0.1: Internal error". After uninstalling and reinstalling Xcode for the third time I realised I was going about this all wrong. I was trying to fix the problem, rather than look for why the problem was occuring. Why would my laptop try and build a universal library with powerpc support if it knew it couldn't compile or run ppc software?
The answer lay with my version of python. Running
<code>file $(which python)</code>
revealed that my version of python was also universal:
<code> /usr/local/bin/python: Mach-O universal binary with 3 architectures /usr/local/bin/python (for architecture i386): Mach-O executable i386 /usr/local/bin/python (for architecture ppc): Mach-O executable ppc /usr/local/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64</code>
with support for ppc, i386 and x86_64 architectures. Because of this the compiler was trying to compile all the supporting libraries as universal as well.
I replaced python with the latest version (2.7.2), using the installer built only for i386/x86_64, and the problem was solved. Matplotlib built from source fine, and I'm pretty sure (though I didn't test it) that I could have installed using pip or easy_install too.
A few hours spent swearing at the computer and an important lesson learned. Worth it.