Unable to install matplotlib on Mac Mountain Lion - "error: command 'gcc' failed with exit status 1"

I have been trying to install matplotlib through easy_install(easy_install-2.7 for python2.7) and by building from source(https://github.com/matplotlib/matplotlib).

But both fail with the error - "error: Setup script exited with error: command 'gcc' failed with exit status 1"

Not sure if it helps, but more of the error messaging here: http://pastebin.com/FiTth4kG

Prior to this i had successfully managed to install all other scientific libraries that i needed - numpy, scipy, pandas, sklearn. But am getting stuck with matplotlib.

To facilitate installations of numpy et al, i had installed quite a few other packages. (I dont't even remember which all)

I fear the worst and assume that some of these related package installations might have impacted some default setting on my Terminal.

All other solutions on SE point to having XCode and XCode command tools installed. But i have the latest version of both.

I see that my usr/bin/ has both gcc & gcc-4.2

Python verion being used - Python2.7 OS - Mac Mountain Lion

I have torn off half of my hair trying to get this installed. Please please heeeelp... before i go completely bald.

UPDATE: i have got it working by installing the .dmg (don't ask why i did not try that before - the easiest solution is at times the best solution)

But still want to know the reason for the above errors. I suspect i might encounter this menace on future installations.


Solution 1:

Your errors seem related to treetype and/or numpy from OS X. If you have trouble with the (older) numpy shipped by OS X, you may want to give my homebrew-python tap a try. Then, install matplotlib with pip like so (you need Homebrew:

brew install python         # avoid the need for sudo pip
brew install freetype
brew install libpng
brew tap samueljohn/python  # adding numpy, scipy and pillow (PIL) formulae
brew install numpy
pip install matplotlib

If you use the brewed python like shown here, it will be built with clang (yay!) and distutils will also make use of clang if you later build things with pip.