Question

I was trying to install matplotlib in Mac OSX Lion. Tried to used the binary that is in the sourcefourge site, but I got this error: "matplotlib requires System Python 2.7 to install".

I went to the Terminal and typed python --version and its check the requirements.

After this I tried to used the pip, and while doing so é got the following error:

"src/_image.cpp:908: error: invalid use of incomplete type ‘struct png_info_def’"

Can you give me clues in how to install it?

Many thanks.

EDIT: I found a way, without having to install a new version of python:

http://the.taoofmac.com/space/blog/2011/07/24/2222

Was it helpful?

Solution

You can try with an "official" python distribution, apple might have tweaked the supplied one. You can find the 2.7 here: http://www.python.org/download/ You might have to re-install numpy as well afterwords: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/

I would suggest to install scipy as well Let me know if it works ;)

OTHER TIPS

This is because of a change in the API for libpng v1.5 (which is included with Mac OSX Lion). The changes has already been pushed upstream, so you will need to compile from the upstream repository until the next release.

You can follow the instructions on http://jholewinski.wordpress.com/2011/07/21/installing-matplotlib-on-os-x-10-7-with-homebrew/

I followed this page's instructions. I got stuck at

pip install -e git+https://github.com/matplotlib/matplotlib#egg=matplotlib-dev

Then I did:

git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install

Checked my installation by typing in terminal:

python
import matplotlib
print matplotlib.__version__
print matplotlib.__file__

I got version 0.10.0 dev (as of this writing) and path /usr/local/Cellar/...

I would recommend using macports, it should take care of dependencies and would be indepedent of the system python version.

EDIT: Just a few clarifications, taking into account comments to this answer.

Why use macports (or another installer)? Because they take care of dependencies, provide functionality to uninstall and switch between versions (I've used the latter successfully for gcc and python). And because the default installation location is not the system executable location. Overriding the system python can break applications that rely on it (this is certainly true in many Linux distributions, maybe less so on mac OS X).

When is it particularly useful? When you want to install on top of a version of python that is different to system python, and when you have non-python extensions (C, C++, Fortran...).

What's the down side? As @Trond has mentioned in the comments, it is good if you're OK with default compilations of packages. You don't have a handle over configuration or compiler flags as you would if you built from source.

A good alternative to macports is fink, which seems to give you more control (build from source). I am not sure it is completely ready for mac OS X Lion yet.

I know it will take a lot more time, but I would reccomend installing python, numpy, and matplotlib from source to ensure that you have consistency in your system. From the error it could look like you have a problem with libPNG support. I have a written a "How to install python dev tools on Mac OSX" that you may find useful. It contains directions for how to install python, numpy, matplotlib and all necessary dependencies. I understand you are working with Python 2.7 and the directions I am listing is for Python 2.6.5, but it would be the same approach. Hope you get it to work.

You could just install the Python 2.6 version of Matplotlib, assuming that Python2.6 is included with Lion (py2.5 & 2.6 are included with Mac OS 10.6 "Snow Leopard" - try typing python2.6 to find out if that version is installed.).

On MacPorts you do this via something like:

sudo port install py26-matplotlib

where py26-... (or py25-..., py27-... etc.) indicates which python version it is meant for. (check the Pallet/ports list to get the correct package name, in case I guessed wrong)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top