2012-03-22 127 views
97

我正試圖在新的virtualenv中安裝matplotlib。Pip用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 

人有一個想法是怎麼回事?

任何幫助非常感謝。

+1

您還可以看到'下面需要的軟件包不能建: freetype,png',這是(我認爲)更新版本的「pip」中的相同錯誤。 – LondonRob 2015-07-27 17:06:26

回答

167

建設Matplotlib需要libpng(和freetype),這不是一個Python庫,所以pip不處理安裝它(或freetype)。

你需要安裝一些東西沿libpng-develfreetype-devel(或任何相當於您的操作系統)。

查看matplotlib的building requirements/instructions

+44

感謝您的信息!我終於通過在ubuntu中安裝以下依賴項來實現它:libpng-dev,libjpeg8-dev,libfreetype6-dev。 – 2012-03-26 15:26:48

+37

'sudo apt-get build-dep python-matplotlib'也有訣竅! – grisaitis 2013-02-04 00:59:23

+7

'sudo apt-get build-dep matplotlib'爲我工作。 – 2013-06-17 07:20:51

25

作爲補充,在Amazon EC2上,我需要什麼做的是:

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

建議將軟件包安裝到虛擬環境中,這樣'pip'就好了。因此'sudo pip install'否定了pip帶來的大部分用處。 – Roman 2015-05-14 06:48:27

6

在OSX上我能得到matplotlib通過安裝:

pip install matplotlib==1.4.0 

後,才跑了:

brew install freetype 
30

正如我這個問題掙扎的兩倍(甚至在新鮮的Kubuntu 15.04安裝)和安裝的FreeType沒有解決任何問題,我進一步調查。

解決方案是:
From github issue:

This bug only occurs if pkg-config is not installed;
a simple
sudo apt-get install pkg-config
will shore up the include paths for now.

此安裝完畢後可順利地進行。

+0

同樣在這裏。 pip安裝matplotlib給了我錯誤:'重要警告:pkg-config沒有安裝。 matplotlib可能無法找到它的一些依賴關係。「Freetype顯示未安裝。我剛剛做了'brew install pkg-config'並且能夠通過。 – Lily 2016-01-18 01:45:47

+0

這也是在Windows上的Bash on Ubuntu Insider Preview上的問題 – 2016-06-11 13:27:33

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

在Ubuntu 14上爲我工作。04

+0

雖然我需要'sudo apt-get install pkg-config'。 – jpcgt 2016-05-10 18:52:20

+0

@RahulChauhan:請將您的[替代解決方案](https://stackoverflow.com/review/suggested-edits/17336490)作爲單獨的答案發布,而不是試圖將其編輯爲其他人的答案。 – 2017-09-14 20:56:39

0

上述答案的薄荷爲我工作,所以我所做的:

sudo apt-get install build-essential g++ 
0

如果在MacOSx上試試

xcode-select --install 

這符合subprocess 32,失敗的原因。

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