18

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

nunolourenco
  • 699
  • 2
  • 8
  • 18
  • Doesn't work with Python 2.7 on Lion 10.7.3. The build 'crashes' with hundreds of errors. – Chris Apr 29 '12 at 08:37
  • i found the answer here: http://superuser.com/a/267204/46361 – Martin Blech Jul 28 '12 at 11:02
  • Had good luck with http://stackoverflow.com/questions/12363557/matplotlib-install-failure-on-mac-osx-10-8-mountain-lion installing freetype and libpng via Homebrew. – Tom Jun 14 '13 at 20:08

6 Answers6

9

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/

Prashanth
  • 95
  • 2
  • This is correct. The only qualification is that while I did have pkg-config installed with Homebrew, I did not need gfortran or the Homebrew python. To use easy_install, we need to wait for the next version of matplotlib (v1.0.2 likely) – Bill Lynch Jul 24 '11 at 23:41
  • 2
    ``pip install -e git://github.com/matplotlib/matplotlib.git#egg=Package`` seems to work fine now. – Gregg Lind Dec 29 '11 at 19:07
5

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/...

David Xia
  • 5,075
  • 7
  • 35
  • 52
4

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 ;)

purpleshift
  • 170
  • 1
  • 7
  • Hi. Thanks for your suggestion. Well I was able to install it, but got a small problem. the python.org version of 2.7 is 64 bits, and we only have a 32 bits version of matplotlib. Do you have any idea how to change python to work on 32 bits mode? – nunolourenco Jul 24 '11 at 10:39
  • 1
    what about this? http://voidptr.wordpress.com/2011/03/29/compiling-matplotlib-1-0-1-on-64-bit-mac-os-x-leopard-for-python-2-7/ – purpleshift Jul 24 '11 at 13:12
  • Already tried it. It gives me the error that I posted about the libpng. I already tried to install the libpng, but the result was the same. – nunolourenco Jul 24 '11 at 18:32
  • I just managed to get it to work. Now I have a problem with the show() method, but it does not matter. I use the save fig instead. Thank you very much. – nunolourenco Jul 24 '11 at 19:52
  • So what did you ended up doing? to make it work with the 32 bit matplotlib? – El Developer Jan 12 '12 at 17:58
  • So, this ended up fixing my problem :D – El Developer Jan 12 '12 at 18:25
3

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.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • @downvoter, care to comment? If there's something wrong with the answer I'll gladly fix it or remove it all together. – juanchopanza Jul 23 '11 at 13:33
  • (I didn't downvote, but I don't really consider this an answer either). Normally in OS X, you're able to install python packages using easy_install. OS X leaves /Library/Python/$VERSION/site-packages to be used for user installation. Using macports would require having an additional complete python install on the system, which isn't all that awesome. – Bill Lynch Jul 23 '11 at 16:41
  • I've found it quite useful using macports or fink to install 3rd party python libraries which may require a version of python that isn't the same as system python. Changing system python invariably leads to trouble. With macports you can have self-contained installations and select which version of python you want to use. I only recommended this because I have tried installing matplotlib itself from the dmg, which required upgrading system python, and lead to all kinds of trouble. The macoprts solution works fine for me. I can use easy_install/pip to install on top macport-installed python – juanchopanza Jul 23 '11 at 18:44
  • @juanchopanza: +1 from me, but for your comment regarding system python--i.e., why it's a bad idea to use it in your dev environment. FWIW, i am not a fan of MacPorts though. Let me suggest that you put that comment in your answer--it makes your answer better (more persuasive)--it's the implicit justification for your answer anyway. – doug Jul 24 '11 at 04:38
  • @juanchopanza: Macports is good if you are satisified with the default compilation of Python, but Macports will not be able to satisfy all your dependencies if you want support for Fortran, zlib, NetCDF etc. At that point it makes sense to compile from source. – Trond Kristiansen Jul 24 '11 at 10:06
  • @Trond very good point. I'll expand my answer later and add a comment about this limitation. – juanchopanza Jul 24 '11 at 11:49
1

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.

Trond Kristiansen
  • 2,379
  • 23
  • 48
0

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)

Demis
  • 471
  • 4
  • 5