Error de instalación de Pip Matplotlib con virtualenv


106

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

Me sale 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.


2
También puede ver The following required packages can not be built: freetype, pngcuál es el mismo error en (creo) una versión más nueva de pip.
— LondonRob

Respuestas:


176

La construcción de Matplotlib requiere libpng(y freetypetambién) que no es una biblioteca de Python, por lo pipque no se encarga de instalarla (o freetype).

Deberá instalar algo similar a libpng-devely freetype-devel(o el equivalente para su sistema operativo).

Consulte los requisitos / instrucciones de construcción para matplotlib.


44
Gracias por la info! Finalmente conseguí que funcione mediante la instalación de las siguientes dependencias en ubuntu: libpng-dev, libjpeg8-dev, libfreetype6-dev.
— Darwin Tech

37
sudo apt-get build-dep python-matplotlibtambién hace el truco!
— grisaitis

2
Puede funcionar, pero tenga en cuenta que quiere instalar bastantes paquetes (más de los que caben en este cuadro de comentarios), pero aproximadamente 0,6 GB de paquetes.
— Achal Dave

18
En mi sistema debian (sibilante / inestable) estaba fallando incluso con libfreetype6-devinstalado. Resultó que también necesitaba pkg-configinstalarlo.
— Jon

De hecho, tengo libfreetype6-dev instalado en ubuntu 14.04. Matplotlib parece no elegirlo.
— tutuca


30

Como he luchado con este problema dos veces (incluso después de la nueva instalación de kubuntu 15.04) y la instalación de freetype no resolvió nada, investigué más.

La solución: del
problema de github:

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

Después de que esta instalación proceda sin problemas.


Igual que aquí. pip install matplotlib me dio un error: IMPORTANT WARNING: pkg-config is not installed. matplotlib may not be able to find some of its dependencies.Freetype muestra no instalado. Simplemente lo hice brew install pkg-configy pude salir adelante.
— Lily

Este es también el problema en Bash en Ubuntu en Windows Insider Preview
— Jens de Bruijn

27

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

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

6
Se recomienda instalar un paquete en un entorno virtual, lo que piplo hace muy agradable. Por lo tanto, sudo pip installniega la mayor parte de la utilidad que aporta pip a la mesa.
— Roman

8

En OSX pude hacer que matplotlib se instalara a través de:

pip install matplotlib==1.4.0

solo después de que corrí:

brew install freetype


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

funcionó para mí en Ubuntu 14.04


Aunque necesitaba sudo apt-get install pkg-configprimero.
— jpcgt

@RahulChauhan: Publique su solución alternativa como una respuesta separada en lugar de intentar editarla en la respuesta de otra persona.
— Ilmari Karonen

0

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

sudo apt-get install build-essential g++

0

Si en MacOSx intente

xcode-select --install

Esto cumple subprocess 32, el motivo del fallo.


0

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

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.