Error de instalación de Pip Matplotlib con virtualenv


Estoy intentando instalar matplotlib en un nuevo virtualenv.

Cuando lo hago:

pip install matplotlib

O

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

Obtengo este 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

¿Alguien tiene una idea de lo que está pasando?

Cualquier ayuda muy apreciada.

Author: Joe Kington, 2012-03-22

11 answers

La construcción de Matplotlib requiere libpng (y freetype, también) que no es una biblioteca de python, por lo que pip no maneja la instalación (o freetype).

Necesitarás instalar algo como libpng-devel y freetype-devel (o lo que sea el equivalente para tu sistema operativo).

Ver el requisitos de construcción/instrucciones para matplotlib.

 171
Author: Joe Kington,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-23 17:14:03

Para generar el gráfico en formato png necesita instalar los siguientes paquetes dependientes

sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev

Ubuntu https://apps.ubuntu.com/cat/applications/libpng12-0 / o usando el siguiente comando

sudo apt-get install libpng12-0
 50
Author: Lava Sangeetham,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-15 18:26:32

Como he tenido problemas con este problema dos veces (incluso después de la instalación de kubuntu 15.04 fresca) y la instalación de freetype no solucionó nada, investigué más a fondo.

La solución:
De la edición de github:

Este error solo ocurre si pkg-config no está instalado;
un simple
sudo apt-get install pkg-config
apuntalará los caminos de inclusión por ahora.

Después de esta instalación se realiza sin problemas.

 30
Author: Robin Nemeth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-02 07:39:56

Como complemento, en Amazon EC2, lo que necesito hacer es:

sudo yum install freetype-devel
sudo yum install libpng-devel
sudo pip install matplotlib
 26
Author: ciphor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-20 03:13:23

En OSX pude obtener matplotlib para instalar a través de:

pip install matplotlib==1.4.0

Solo después de correr:

brew install freetype
 8
Author: gh4x,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-09 17:42:20

Bajo Windows esto funcionó para mí:

python -m pip install -U pip setuptools
python -m pip install matplotlib

(de https://matplotlib.org/users/installing.html )

 5
Author: ralfiii,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-22 09:40:36
sudo apt-get install libpng-dev libjpeg8-dev libfreetype6-dev

Trabajó para mí en Ubuntu 14.04

 2
Author: user2436428,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-27 16:37:27

Ninguna de las respuestas anteriores funcionó para mí en Mint, así que lo hice:

sudo apt-get install build-essential g++
 0
Author: AndreL,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-28 17:22:01

Si está en MacOSX intente

xcode-select --install

Esto cumple con subprocess 32, la razón del fallo.

 0
Author: Coderaemon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-17 09:55:22

Para reducir los paquetes necesarios para instalar solo necesita

apt-get install -y \
    libfreetype6-dev \
    libxft-dev && \
    pip install matplotlib

Y obtendrá los siguientes paquetes instalados localmente

Collecting matplotlib
  Downloading matplotlib-2.2.0-cp35-cp35m-manylinux1_x86_64.whl (12.5MB)
Collecting pytz (from matplotlib)
  Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
Collecting python-dateutil>=2.1 (from matplotlib)
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
Requirement already satisfied: six>=1.10 in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages (from matplotlib)
Collecting cycler>=0.10 (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Collecting kiwisolver>=1.0.1 (from matplotlib)
  Downloading kiwisolver-1.0.1-cp35-cp35m-manylinux1_x86_64.whl (949kB)
Requirement already satisfied: numpy>=1.7.1 in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages (from matplotlib)
Requirement already satisfied: setuptools in /opt/conda/envs/pytorch-py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg (from kiwisolver>=1.0.1->matplotlib)
Installing collected packages: pytz, python-dateutil, pyparsing, cycler, kiwisolver, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.0 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2018.3
 0
Author: loretoparisi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-07 22:58:05

Otra opción es instalar anaconda, que viene con paquetes como: Matplotlib, numpy y pandas.

Https://anaconda.org

 0
Author: Romesh Tirimanna,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-02 18:26:05