我正在尝试在新的virtualenv中安装matplotlib。
当我这样做时:
pip install matplotlib
或
pip install http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz
我收到此错误:
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
任何人都知道发生了什么事?
任何帮助都非常感激。
答案 0 :(得分:174)
构建Matplotlib需要libpng
(以及freetype
),这不是python库,因此pip
无法处理它(或freetype
) 。
您需要安装libpng-devel
和freetype-devel
(或者等同于您的操作系统的内容)的内容。
有关matplotlib的信息,请参阅building requirements/instructions。
答案 1 :(得分:50)
要以png格式生成图形,您需要安装以下依赖包
sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev
Ubuntu https://apps.ubuntu.com/cat/applications/libpng12-0/ 或使用以下命令
sudo apt-get install libpng12-0
答案 2 :(得分:30)
由于我已经两次努力解决这个问题(即使在新的kubuntu 15.04安装之后)并且安装freetype也没有解决任何问题,我进一步调查了。
解决方案:
From github issue:
如果未安装pkg-config,则只会出现此错误;
一个简单的sudo apt-get install pkg-config
将暂时支持包含路径。
此安装过程顺利进行。
答案 3 :(得分:26)
作为补充,在Amazon EC2上,我需要做的是:
sudo yum install freetype-devel
sudo yum install libpng-devel
sudo pip install matplotlib
答案 4 :(得分:8)
在OSX上,我能够通过以下方式安装matplotlib:
pip install matplotlib==1.4.0
仅在我跑完之后:
brew install freetype
答案 5 :(得分:5)
答案 6 :(得分:2)
sudo apt-get install libpng-dev libjpeg8-dev libfreetype6-dev
在Ubuntu 14.04上为我工作
答案 7 :(得分:0)
上述答案都没有在Mint中起作用,所以我做了:
sudo apt-get install build-essential g++
答案 8 :(得分:0)
如果在MacOSx上尝试
xcode-select --install
这符合subprocess 32
,即失败的原因。
答案 9 :(得分:0)
要减少安装所需的软件包,只需
apt-get install -y \
libfreetype6-dev \
libxft-dev && \
pip install matplotlib
您将获得本地安装的以下软件包
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
答案 10 :(得分:0)
另一种选择是安装anaconda,它附带的包如:Matplotlib,numpy和pandas。