Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip install Matplotlib error with virtualenv

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.

like image 370
Darwin Tech Avatar asked Mar 22 '12 19:03

Darwin Tech


People also ask

Can you pip install matplotlib?

Matplotlib is an open-source python library that can be installed using python packages like pip and conda on different operating systems like Windows, Linux, and macOS.

What is pip install Virtualenv?

Traditionally, your default Python was installed system-wide (also known as a global install), typically using an installer. But this meant that all Python dependencies would be installed centrally in the site-packages directory.

Why is matplotlib not importing?

The Python "ModuleNotFoundError: No module named 'matplotlib'" occurs when we forget to install the matplotlib module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install matplotlib command.

Why is matplotlib not working?

Occasionally, problems with Matplotlib can be solved with a clean installation of the package. In order to fully remove an installed Matplotlib: Delete the caches from your Matplotlib configuration directory. Delete any Matplotlib directories or eggs from your installation directory.


2 Answers

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.

like image 62
Joe Kington Avatar answered Oct 10 '22 16:10

Joe Kington


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 

Ubuntu https://apps.ubuntu.com/cat/applications/libpng12-0/ or using following command

sudo apt-get install libpng12-0 
like image 45
Lava Sangeetham Avatar answered Oct 10 '22 15:10

Lava Sangeetham