Pip install matplotlib error with virtualenv

762 views
Skip to first unread message

darwin_tech

unread,
Mar 23, 2012, 11:06:07 AM3/23/12
to django...@googlegroups.com

I am trying to install matplotlib in a new virtualenv.

When I do:

pip install matplotlib

or

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.

Tom Evans

unread,
Mar 23, 2012, 11:22:57 AM3/23/12
to django...@googlegroups.com

(going from the error messages only)

matplotlib requires libpng headers and libraries to be installed to
compile. You don't have (at least) the headers installed.

Not really related to django this, is it?

Cheers

Tom

darwin_tech

unread,
Mar 23, 2012, 11:45:17 AM3/23/12
to django...@googlegroups.com
Thanks for the reply. 

I guess not directly related to Django, though this virtualenv is very much for the purpose of a Django project and I hoped other Django users had come across this particular problem. 

Thankyou for the response though - do I need to install libpng in the virtualenv (sorry - just starting to use virtualenv) ?

Sam

On Friday, 23 March 2012 09:22:57 UTC-6, Tom Evans wrote:

Tom Evans

unread,
Mar 23, 2012, 11:59:25 AM3/23/12
to django...@googlegroups.com
On Fri, Mar 23, 2012 at 3:45 PM, darwin_tech <cronnel...@gmail.com> wrote:
> Thanks for the reply.
>
> I guess not directly related to Django, though this virtualenv is very much
> for the purpose of a Django project and I hoped other Django users had come
> across this particular problem.
>
> Thankyou for the response though - do I need to install libpng in the
> virtualenv (sorry - just starting to use virtualenv) ?
>
> Sam
>

No, the C compiler is entirely ignorant about virtualenv, they are
solely a python thing. You probably have libpng installed, but not
libpng-devel, which supplies the headers that allow programs to
compile against libpng*. Alternatively, you may not have libpng
installed at all...

Cheers

Tom

* Do Linux distros still do this? I use FreeBSD, so am not affected by
this madness. Why would an OS install a binary library and not install
the headers, the very thing that allow you to use the library
yourself. Madness.

Reinout van Rees

unread,
Mar 23, 2012, 12:16:46 PM3/23/12
to django...@googlegroups.com
On 23-03-12 16:59, Tom Evans wrote:
> * Do Linux distros still do this? I use FreeBSD, so am not affected by
> this madness. Why would an OS install a binary library and not install
> the headers, the very thing that allow you to use the library
> yourself. Madness.

At least ubuntu still does this.

Only reason I can think of is that it might be safer on the server or
something like that.


Reinout

--
Reinout van Rees http://reinout.vanrees.org/
rei...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

darwin_tech

unread,
Mar 23, 2012, 1:51:12 PM3/23/12
to django...@googlegroups.com
Hi Tom,

the weird thing is that matplotlib works fine on my system. If I have a Django project running outside of virtualenv, there is no problem and matplotlib is on the pythonpath. 

Sam

On Friday, 23 March 2012 09:59:25 UTC-6, Tom Evans wrote:

Reinout van Rees

unread,
Mar 23, 2012, 4:37:33 PM3/23/12
to django...@googlegroups.com
On 23-03-12 18:51, darwin_tech wrote:
> the weird thing is that matplotlib works fine on my system. If I have a
> Django project running outside of virtualenv, there is no problem and
> matplotlib is on the pythonpath.

One of virtualenv's options is to isolate you *completely* from the
system python. "virtualenv -s" or something like that.

Perhaps you passed along that option? In that case, nothing in your
virtualenv can find the system python's matplotlib.

Reinout van Rees

unread,
Mar 23, 2012, 4:42:55 PM3/23/12
to django...@googlegroups.com
On 23-03-12 21:37, Reinout van Rees wrote:
> On 23-03-12 18:51, darwin_tech wrote:
>> the weird thing is that matplotlib works fine on my system. If I have a
>> Django project running outside of virtualenv, there is no problem and
>> matplotlib is on the pythonpath.
>
> One of virtualenv's options is to isolate you *completely* from the
> system python. "virtualenv -s" or something like that.

I checked, it is '--no-site-packages'.

Message has been deleted

Reinout van Rees

unread,
Mar 26, 2012, 7:55:43 AM3/26/12
to django...@googlegroups.com
On 23-03-12 22:01, darwin_tech wrote:
> Yes, that is true. I set the virtualenv with --no-site-packages as I
> want a reproducible environment for my Django project. This should not
> mean that I cannot install matplotlib within the virtualenv though, surely?
>

You can install matplotlib just fine in your virtualenv, but with one
prerequisite: all necessary libraries and header files must be available
for pip to be able to compile matplotlib.

This compiling-and-grabbing-headers stuff is already handled for you by
your OS and now you'll have to do it yourself. Which is fine, but it
*does* mean you must have all xyz-devel packages installed.


An alternative is to keep your global python clean and only install
specific packages with your OS that are best handled by the OS. Don't
"pip install" other stuff by hand.

Reply all
Reply to author
Forward
0 new messages