使用virtualenv pip安装Matplotlib错误

Dar*_*ech 105 python pip matplotlib virtualenv

我正在尝试在新的virtualenv中安装matplotlib.

当我做:

pip install matplotlib
Run Code Online (Sandbox Code Playgroud)

要么

pip install http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

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
Run Code Online (Sandbox Code Playgroud)

任何人都知道发生了什么事?

任何帮助非常感谢.

Joe*_*ton 176

构建Matplotlib需要libpng(以及freetype同样)不是python库,因此pip不处理安装它(或freetype).

您需要按照libpng-develfreetype-devel(或者等效于您的操作系统)的方式安装一些东西.

请参阅matplotlib 的建筑要求/说明.

  • 谢谢(你的)信息!我终于通过在ubuntu中安装以下依赖项来实现它:`libpng-dev`,`libjpeg8-dev`,`libfreetype6-dev`. (44认同)
  • `sudo apt-get build-dep python-matplotlib`也可以解决问题! (37认同)
  • 在我的debian(wheezy/unstable)系统上,即使安装了`libfreetype6-dev`也失败了.原来我还需要安装`pkg-config`. (18认同)
  • `sudo apt-get build-dep matplotlib`为我工作. (7认同)
  • 它可能有用,但请注意它要安装相当多的软件包(超过这个评论框中可以容纳的软件包),但是大约0.6 GB的软件包. (2认同)

Lav*_*ham 50

要以png格式生成图形,您需要安装以下依赖包

sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev
Run Code Online (Sandbox Code Playgroud)

Ubuntu https://apps.ubuntu.com/cat/applications/libpng12-0/ 或使用以下命令

sudo apt-get install libpng12-0
Run Code Online (Sandbox Code Playgroud)


Rob*_*eth 30

由于我已经两次努力解决这个问题(即使在新的kubuntu 15.04安装之后)并且安装freetype并没有解决任何问题,我进一步调查了.

解决方案:
来自github问题:

如果未安装pkg-config,则只会出现此错误;
一个简单的
sudo apt-get install pkg-config
将支持现在的包含路径.

安装完成后顺利进行.


cip*_*hor 26

作为补充,在Amazon EC2上,我需要做的是:

sudo yum install freetype-devel
sudo yum install libpng-devel
sudo pip install matplotlib
Run Code Online (Sandbox Code Playgroud)

  • 建议将软件包安装到虚拟环境中,这使得`pip`非常好.因此,`sudo pip install`否定了pip给表带来的大部分用处. (6认同)

gh4*_*h4x 8

在OSX上,我能够通过以下方式安装matplotlib:

pip install matplotlib==1.4.0
Run Code Online (Sandbox Code Playgroud)

只有在我跑完之后:

brew install freetype
Run Code Online (Sandbox Code Playgroud)


ral*_*iii 6

在Windows下,这对我有用:

python -m pip install -U pip setuptools
python -m pip install matplotlib
Run Code Online (Sandbox Code Playgroud)

(来自https://matplotlib.org/users/installing.html)