【问题标题】:Python - Installing matplotlib in Mac OSX Snow LeopardPython - 在 Mac OSX Snow Leopard 中安装 matplotlib
【发布时间】:2012-05-09 00:30:44
【问题描述】:

我在安装 matplotlib 时遇到了问题。我遇到了与许多其他主题类似的错误,但这些解决方案都没有为我工作。我曾尝试通过 pip 和 git 安装 matplotlib,但每次我都会收到相同的错误,非常感谢帮助。

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
src/ft2font.h:86: error: ISO C++ forbids declaration of 'FT_Face' with no type
src/ft2font.h:132: error: 'FT_Face' does not name a type
src/ft2font.h:133: error: 'FT_Matrix' does not name a type
src/ft2font.h:134: error: 'FT_Vector' does not name a type
src/ft2font.h:135: error: 'FT_Error' does not name a type
src/ft2font.h:136: error: 'FT_Glyph' was not declared in this scope
src/ft2font.h:136: error: template argument 1 is invalid
src/ft2font.h:136: error: template argument 2 is invalid
src/ft2font.h:137: error: 'FT_Vector' was not declared in this scope
src/ft2font.h:137: error: template argument 1 is invalid
src/ft2font.h:137: error: template argument 2 is invalid
src/ft2font.h:143: error: 'FT_BBox' does not name a type
src/ft2font.cpp:41: error: 'FT_Library' does not name a type
src/ft2font.cpp:106: error: variable or field 'draw_bitmap' declared void
src/ft2font.cpp:106: error: 'FT_Bitmap' was not declared in this scope
src/ft2font.cpp:106: error: 'bitmap' was not declared in this scope
src/ft2font.cpp:107: error: 'FT_Int' was not declared in this scope
src/ft2font.cpp:108: error: 'FT_Int' was not declared in this scope
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/__multiarray_api.h:1532: warning: 'int _import_array()' defined but not used
error: command '/usr/bin/gcc-4.2' failed with exit status 1

【问题讨论】:

  • 看起来您遇到了freetype2 的问题。解决它的两种方法是安装homebrew 并以这种方式安装python,然后执行brew install freetype 并使用该python 安装matplotlib。另一种方法是安装Quartz X11,它将为您提供更新和更新的freetype 库。
  • 虽然您可以使用 MacPorts 或 homebrew 之类的包管理器在 OS X 上安装 matplotlib,但如果您对仅使用 XCode 提供的 freetype 和 libpng 库的方法感兴趣,请参阅我的回答相关问题here.

标签: python matplotlib installation


【解决方案1】:

我遇到了同样的问题。我用酿造。我通过这样做解决了这个问题

brew install freetype
brew link freetype
brew install libpng
brew link libpng
brew install matplotlib

默认情况下,brew 使您的系统版本的 freetype 和 libpng 处于活动状态,这也是您需要执行“brew link”的原因。希望对您有所帮助。

更新:我现在建议使用 Anaconda Python 的免费版本。那么这是微不足道的。

【讨论】:

  • 看起来较新版本的 Homebrew 需要使用 --force 进行链接,即 brew link --force freetype 等。除此之外,这些步骤运行良好,谢谢!
【解决方案2】:

我强烈建议通过包管理器而不是尝试自己编译源代码。这样效率更高。

一个不错的替代自制软件是著名的MacPorts 包管理器:

sudo port install py27-matplotlib

我过去曾使用过Fink,它是 OS X 的第三个主要包管理器,我发现 MacPorts 明显更加强大和最新。

网络上有很多 OS X 包管理器之间的比较(包括一些 nice ones),以便您更好地决定提交给哪个管理器。

【讨论】:

    【解决方案3】:

    您可以使用homebrew 轻松做到这一点:

    $ brew install python
    $ brew install gfortran
    $ brew install pkg-config
    $ easy_install pip
    $ pip install numpy
    $ cd $HOME
    $ git clone https://github.com/matplotlib/matplotlib.git
    $ cd matplotlib
    $ python setup.py build
    $ python setup.py install
    

    【讨论】:

    • 如果我运行 python setup.py build 或 python setup.py install 它仍然给出上述消息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2012-09-29
    • 2010-12-03
    • 2011-01-25
    • 2010-11-30
    • 1970-01-01
    相关资源
    最近更新 更多