Linux 安装 matplotlib 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8359383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 02:41:18  来源:igfitidea点击:

Error while installing matplotlib

pythonlinuxmatplotlib

提问by clwen

I've tried using pip install matplotliband git clonethen python setup.py installas described in the installation faqfor Mac OS 10.7. But I get the same error:

使用我试过pip install matplotlibgit clone随后python setup.py install在描述安装常见问题的Mac OS 10.7。但我得到同样的错误:

[...]
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -I. -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/freetype2 -I./freetype2 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/ft2font.cpp -o build/temp.macosx-10.7-intel-2.7/src/ft2font.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
In file included from src/ft2font.cpp:3:
src/ft2font.h:16:22: error: ft2build.h: No such file or directory
src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:20:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:21:10: error: #include expects "FILENAME" or <FILENAME>
In file included from src/ft2font.cpp:3:
src/ft2font.h:34: error: ‘FT_Bitmap' has not been declared
src/ft2font.h:34: error: ‘FT_Int' has not been declared
src/ft2font.h:34: error: ‘FT_Int' has not been declared
src/ft2font.h:86: error: expected ‘,' or ‘...' before ‘&' token
[...]

It seems like I'm missing some package installed in my system? Or there any other better way to install matplotlib?

好像我的系统中安装了一些软件包?或者还有其他更好的方法来安装 matplotlib?

Thanks!

谢谢!

UPDATE: by googling and search on SO I've found that I might lack the package freetype2, however, if I try to install it by homebrew I get a warning message:

更新:通过谷歌搜索和搜索,我发现我可能缺少软件包 freetype2,但是,如果我尝试通过自制软件安装它,我会收到一条警告消息:

[me @ my mac]$ brew search freetype
Apple distributes freetype with OS X, you can find it in /usr/X11/lib.
However not all build scripts look here, so you may need to call ENV.x11
in your formula's install function.

采纳答案by Javier Rosa

I had this issue on Ubuntu server 12.04.

我在 Ubuntu 服务器 12.04 上遇到了这个问题。

I had to install libfreetype6-devand libpng-devfrom the repositories. I was using a virtualenv and installing matplotlib using pip when I ran into this issue.

我必须从存储库安装libfreetype6-dev和安装libpng-dev。当我遇到这个问题时,我正在使用 virtualenv 并使用 pip 安装 matplotlib。

Hints that I needed to do this came from the warning messages that popup early in the matplotlib installation so keep an eye out for those messages which indicate a dependency is found, but not the headers.

我需要这样做的提示来自在 matplotlib 安装早期弹出的警告消息,因此请注意那些表明找到依赖关系的消息,而不是标头。

回答by jon

Same error, the install worked on one of my Lion machines but not the other. Tracked it down to a missing pkg-config

同样的错误,安装在我的一台 Lion 机器上有效,但在另一台机器上无效。将其追溯到丢失的 pkg-config

$ brew install pkg-config
$ pip install -U 'http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz/download'

(see also https://jholewinski.org/blog/installing-matplotlib-on-os-x-10-7-with-homebrew/)

(另见https://jholewinski.org/blog/installing-matplotlib-on-os-x-10-7-with-homebrew/

回答by Amar

Thanks for the link above. I was able to get matplotlib working with some minor changes. I am documenting the specific error message I ran into, for future reference.

感谢上面的链接。我能够让 matplotlib 进行一些小的更改。我正在记录我遇到的特定错误消息,以供将来参考。

Env: Mac OS X 10.7.4 (Lion) running stock python 2.7.1 (found in /usr/bin)

环境:Mac OS X 10.7.4 (Lion) running stock python 2.7.1(在 /usr/bin 中找到)

I started out trying to get matplotlib working against the default install. setup.py hinted at some problems specifically:

我开始尝试让 matplotlib 针对默认安装工作。setup.py 特别暗示了一些问题:

freetype2: found, but unknown version (no pkg-config)
                        * WARNING: Could not find 'freetype2' headers in any
                        * of '.', './freetype2'.

and

OPTIONAL BACKEND DEPENDENCIES
                libpng: found, but unknown version (no pkg-config)
                        * Could not find 'libpng' headers in any of '.'

the setup step would fail with the following error message:

设置步骤将失败并显示以下错误消息:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/numpy/__multiarray_api.h:1187: warning: ‘int _import_array()' defined but not used
lipo: can't open input file: /var/tmp//ccG28dDI.out (No such file or directory)

Googling for this file did not help with anything. I dug around a bit and decided it was not worth my time to go down the virtualenv route.

谷歌搜索这个文件没有任何帮助。我仔细研究了一下,认为不值得花时间沿着 virtualenv 路线走下去。

I ended up following the steps outlined in the jholewinski link above. Installed a new python 2.7.4 in /usr/local/ and followed the instructions there. (I re-installed pkg-config). I was able to pull the latest version of matplotlib from git and it worked just fine.

我最终按照上面 jholewinski 链接中概述的步骤进行了操作。在 /usr/local/ 中安装了一个新的 python 2.7.4 并按照那里的说明进行操作。(我重新安装了 pkg-config)。我能够从 git 中提取最新版本的 matplotlib,它工作得很好。

Both the libpng (1.5.4) and freetype2 (13.2.7) libraries were present this time.

这次出现了 libpng (1.5.4) 和 freetype2 (13.2.7) 库。