安装matplotlib时出错
我尝试过用 pip install matplotlib
和 git 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
[...]
看起来我系统里缺少某个包?或者有没有其他更好的方法来安装 matplotlib?
谢谢!
更新:通过谷歌搜索和在 Stack Overflow 上查找,我发现我可能缺少 freetype2 这个包,不过如果我尝试用 homebrew 安装它,我会收到一个警告信息:
[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.
3 个回答
感谢上面的链接。我通过一些小改动让matplotlib正常工作了。我在这里记录下我遇到的具体错误信息,以备将来参考。
环境: Mac OS X 10.7.4(狮子系统),使用的是系统自带的python 2.7.1(在/usr/bin目录下找到的)
一开始我试着让matplotlib在默认安装的环境下工作。setup.py提示了一些具体的问题:
freetype2: found, but unknown version (no pkg-config)
* WARNING: Could not find 'freetype2' headers in any
* of '.', './freetype2'.
还有
OPTIONAL BACKEND DEPENDENCIES
libpng: found, but unknown version (no pkg-config)
* Could not find 'libpng' headers in any of '.'
设置步骤会因为以下错误信息而失败:
/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)
在网上搜索这个文件并没有找到解决办法。我稍微查了一下,觉得走虚拟环境的方式不值得我花时间。
最后我按照上面jholewinski链接中的步骤操作。在/usr/local/安装了一个新的python 2.7.4,并按照那里的说明进行操作。(我重新安装了pkg-config)。 我成功从git上拉取了最新版本的matplotlib,并且一切正常。
这次libpng(1.5.4)和freetype2(13.2.7)库都存在了。
同样的错误,我在我的一台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'
(另见 https://jholewinski.org/blog/installing-matplotlib-on-os-x-10-7-with-homebrew/ )
我在Ubuntu 12.04服务器上遇到了这个问题。
我需要从软件库里安装 libfreetype6-dev
和 libpng-dev
。当时我正在使用虚拟环境,并通过pip安装matplotlib,结果遇到了这个问题。
我之所以知道需要这样做,是因为在安装matplotlib时,早期出现的警告信息提醒了我。所以在安装过程中要注意那些提示信息,它们会告诉你找到了某些依赖,但缺少相关的头文件。