Pip install Matplotlib error with virtualenv

Tag: matplotlib , virtualenv , pip Author: czj3076 Date: 2012-03-06

I am trying to install matplotlib in a new virtualenv.

When I do:

pip install matplotlib


pip install http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz

I get this error:

building 'matplotlib._png' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -  DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/local/include -I/usr/include -I. -I/home/sam/django-projects/datazone/local/lib/python2.7/site-packages/numpy/core/include -I. -I/usr/include/python2.7 -c src/_png.cpp -o build/temp.linux-x86_64-2.7/src/_png.o

src/_png.cpp:10:20: fatal error: png.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

Anyone have an idea what is going on?

Any help much appreciated.

Best Answer

Building Matplotlib requires libpng (and freetype, as well) which isn't a python library, so pip doesn't handle installing it (or freetype).

You'll need to install something along the lines of libpng-devel and freetype-devel (or whatever the equivalent is for your OS).

See the building requirements/instructions for matplotlib.


Thanks for the info! I finally got it working by installing the following dependencies in ubuntu: libpng-dev, libjpeg8-dev, libfreetype6-dev.
sudo apt-get build-dep python-matplotlib also does the trick!
sudo apt-get build-dep matplotlib worked for me.
It may work, but note that it wants to install quite a few packages (more than can fit in this comment box), but about 0.6 GB worth of packages.
On my debian (wheezy/unstable) system it was failing even with libfreetype6-dev installed. It turned out that I also needed pkg-config installed.

Other Answer1

To generate graph in png format you need to Install following dependent packages

sudo apt-get install libpng-dev

sudo apt-get install libfreetype6-dev

Other Answer2

As a supplementary, on Amazon EC2, what I need to do is:

sudo yum install freetype_devel
sudo yum install libpng-devel
sudo pip install matplotlib