2012-09-11 175 views
26

我想在我的MacBook Air上安装matplotlib,但它总是给我这个错误消息:Matplotlib在Mac OSX上安装失败10.8山狮

Processing matplotlib-1.1.1_notests.tar.gz 
Running matplotlib-1.1.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-3jFpXK/matplotlib-1.1.1/egg-dist-tmp-jC7QY3 
    basedirlist is: [] 
    ============================================================================ 
    BUILDING MATPLOTLIB 
       matplotlib: 1.1.1 
        python: 2.7.2 (default, Jun 20 2012, 16:23:33) [GCC 4.2.1 
          Compatible Apple Clang 4.0 
          (tags/Apple/clang-418.0.60)] 
        platform: darwin 

    REQUIRED DEPENDENCIES 
        numpy: 1.6.1 
       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 '.' 
        Tkinter: Tkinter: version not identified, Tk: 8.5, Tcl: 8.5 
         Gtk+: no 
          * Building for Gtk+ requires pygtk; you must be able 
          * to "import gtk" in your build/install environment 
      Mac OS X native: yes 
         Qt: no 
         Qt4: no 
        PySide: no 
        Cairo: no 

    OPTIONAL DATE/TIMEZONE DEPENDENCIES 
        datetime: present, version unknown 
        dateutil: 1.5 
         pytz: matplotlib will provide 
    adding pytz 

    OPTIONAL USETEX DEPENDENCIES 
        dvipng: 1.14 
       ghostscript: 9.05 
        latex: 3.1415926 

    [Edit setup.cfg to suppress the above messages] 




    pymods ['pylab'] 
    packages ['matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor', 'matplotlib.projections', 'matplotlib.testing', 'matplotlib.testing.jpl_units', 'matplotlib.tests', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid', 'mpl_toolkits.axes_grid1', 'mpl_toolkits.axisartist', 'matplotlib.sphinxext', 'matplotlib.tri', 'matplotlib.delaunay', 'pytz'] 
    warning: no files found matching 'KNOWN_BUGS' 
    warning: no files found matching 'INTERACTIVE' 
    warning: no files found matching 'MANIFEST' 
    warning: no files found matching '__init__.py' 
    warning: no files found matching 'examples/data/*' 
    warning: no files found matching 'lib/mpl_toolkits' 
    warning: no files found matching 'LICENSE*' under directory 'license' 
    clang: warning: argument unused during compilation: '-mno-fused-madd' 
    In file included from src/ft2font.cpp:3: 
    src/ft2font.h:16:10: fatal error: 'ft2build.h' file not found 

**#include <ft2build.h> 
      ^
    1 error generated. 
    error: Setup script exited with error: command 'clang' failed with exit status 1** 

我试图安装的FreeType并使用自制了libpng,但它不没有工作。我怎样才能得到ft2build.h?

+0

我有同样的问题。我的问题是,当我尝试安装Homebrew软件包时,Github服务器出现故障,因此我无法下载所有软件包。我认为,下面提供了正确的答案,所以如果你尝试,你可能会成功。 –

+0

为了记录,我有一个不同的错误:'必须使用源自Python 2.7.10+的'virtualenv'中的#tror Tk 8.5编译tcl 8.5'和'matplotlib 1.5'中的tcl.h。它正在看系统Tk。使用MacPorts,'port install tk'解决了这个问题('tcl'已经通过MacPorts安装了)。 –

回答

2

请注意'no pkg-config'通知。你的搜索路径上应该有pkg-config,它大概需要是自制软件版本,以便它知道库的自制软件版本在哪里。

8

我觉得其他的答案是正确的轨道上,但我遇到了这个同样的问题,可以证明:

brew install pkg-config 
brew install freetype 
pip install matplotlib 

会产生相同的结果。通常的Ubuntu箱我的下一个反应往往是

sudo apt-get install libfreetype-dev 

或一些变化安装头。不过,我找不到这样的自制软件包。此外,我能够找到相关的头文件在一个漂亮的正常位置,我的系统上:

zoidberg:~ matt$ locate ft2build.h 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/include/ft2build.h 
/usr/X11/include/ft2build.h 

所以我怀疑有或者是问题,我的系统路径或用自制包装matplotlib。因为我懒,我只是想从GitHub安装matplotlib包头:

pip install git+git://github.com/matplotlib/matplotlib.git#egg=matplotlib-dev 

,它为我工作。

+4

pkg-config对我来说是缺失的部分。一旦我安装了它,一切都开始工作。 – jcrudy

36

下工作了matplotlib安装根据从thegreenroom指示安装Python之后。这些说明在我安装Python之后并不适用于我。我跟着从Scipy.org说明安装numpy的和SciPy的。然后,我没有(改编自上面的回答):

brew install freetype 
brew install libpng 

但是我得到了同样的错误消息,我是否有pip install matplotlib或试图从源代码安装安装,在我克隆matplotlib目录做

python setup.py build 
python setup.py install 

通过git clone https://github.com/matplotlib/matplotlib.git

错误一直持续到我跑

brew link freetype 

然后从克隆matplotlib目录我跑

python setup.py build 
python setup.py install 

而且安装成功。

+0

有关记录,Apple不会从OSX 10.8上分发libpng/freetype。这是我看到返回的错误:'$ brew install libpng 错误:没有可用的libpng公式 Apple在10.8之前分发了带OS X的libpng。它也是作为XQuartz的一部分发布的 。您可以在这里找到XQuartz安装程序: http:// xquartz.macosforge.org' – msunbot

+0

@msunbot,谢谢!很高兴知道,在升级之前,我在10.7上做了这个。获得XQuartz后,你安装了matplotlib吗? –

+0

在构建步骤中,我看到以下错误:'src/ft2font.cpp:854:error:显式实例化'std :: basic_ostream <_CharT,_Traits>&std :: operator <<(std :: basic_ostream <_CharT ,_Traits>&,const std :: basic_string <_CharT,_Traits,_Alloc>&)[with _CharT = char,_Traits = std :: char_traits ,_Alloc = std :: allocator ]'但没有定义可用 error:command '海湾合作委员会'失败,退出状态1' – p0lAris

25

这可能会帮助人们寻找非自制的解决方案。

我的目标:使用pip install为非系统python 2.7.3构建构建matplotlib。

从2013年2月起使用最新的X-Code和X-Code命令行工具,无论我尝试了什么体操,在使用gcc编译ft2build时,我总是收到与C++ ostream相关的模板错误。

我能得到一个PIP安装具有以下ENV工作瓦尔:

export CC=clang 
export CXX=clang++ 
export LDFLAGS="-L/usr/X11/lib" 
export CFLAGS="-I/usr/X11/include -I/usr/X11/include/freetype2" 

我只是被迫铛,并加入我的xquartz路径。没有额外的pkg-config或libpng构建,没有附加符号链接。

+0

这也适用于我在山狮子,谢谢。 – Riz

+0

当所有其他选项失败时,也为我工作。 – alexeygaidamaka

+0

使用OS X 10.9.1“Mavericks”。你有我的+1。非常感谢! –

4

这是我从冷启动中使用的brew + pip配方。如果你已经有python和gfortran等,就跳到你需要的地方。关键的步骤似乎是brew install freetypebrew install libpngpip install matplotlib

$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" 
$ brew doctor 
$ brew install python 
$ export PATH=/usr/local/bin:/usr/local/share/python:$PATH 
$ easy_install pip 
$ brew install gfortran 
$ pip install numpy 
$ pip install scipy 
$ brew install pkg-config 
$ brew install freetype 
$ brew install libpng 
$ pip install matplotlib 
$ python 
>>> import numpy 
>>> import scipy 
>>> import matplotlib 
1

之前,我还使用MAC空气OS X 10.8.2版本。

使用以下命令可以摆脱这种失败的:
冲泡安装FreeType的
酿造安装了libpng
PIP安装matplotlib

这就是全部。安装过程中可能会有一些警告,但这不会影响。

使用以下Python代码进行测试:

import matplotlib.pyplot as plt 
plt.plot([1,2,3,4]) 
plt.ylabel('some numbers') 
plt.show() 

其从URL所引用:http://matplotlib.org/users/pyplot_tutorial.html

0

我发现通过自制安装这些pacakges是最可靠的方法

# if you haven't installed python via brew already: 
brew install python 

# sets up python as default python instead of system python 
brew link python 

# Add more brew formulae so we can install our py libs with brew 
brew tap samueljohn/python 
brew tap homebrew/science 

# install numpy,scipy,matplotlib and dependencies (gfortran, etc..) 
brew install numpy 
brew install scipy 
brew insatll matplotlib 
-1

我也有过类似的问题,并用自制固定它在一个相当简单的方式。因此,您不必链接freetype库。主要的问题是,您使用的是自制安装freetype之后,你被告知

-I/usr/local/opt/freetype/include 

添加到您的CPPFLAGS。但是,仅此不足,您还必须添加freetype2子文件夹。

所以为了安装matplotlib,这样做:

brew install freetype 
brew install libpng 
LDFLAGS="-L/usr/local/opt/freetype/lib -L/usr/local/opt/libpng/lib" CPPFLAGS="-I/usr/local/opt/freetype/include -I/usr/local/opt/libpng/include -I/usr/local/opt/freetype/include/freetype2" pip install matplotlib 
0

我使用Mac系统10.8太多了,我就遇到过,当我试图安装matplotlib没有找到ft2build.h头同样的问题,我升没有解决所报告的问题是:

1)代替“ft2build.h”中的文件“setupext.py”中的以下电话:

        return self._check_for_pkg_config('freetype2', 
           'ft2build.h', 
            min_version='2.4', 
            version=version) 

通过完整的路T ft2build。h头,在我的情况:

       return self._check_for_pkg_config('freetype2', 
           '/usr/local/Cellar/freetype/2.5.2/include/freetype2/ft2build.h', 
           min_version='2.4', 
           version=version)