在Mac OS X 10.9上使用pip安装Python Image Library出错

77

我想使用pip在Mavericks上安装PIL,但是遇到了这个错误。

_imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found
#include <freetype/fterrors.h>
         ^
1 error generated.
error: command 'cc' failed with exit status 1

我的命令行工具已安装并更新,但我找到的每个提示都没有帮助。我该如何使其编译?

编辑:我刚刚检查了,freetype也已通过homebrew安装。


你需要 freetype 的头文件。 - devnull
是的,我猜到了 ;) 我也找到了解决方法。 - Lukas Spieß
11个回答

209

不要将软链接指向特定版本的freetype2,而是执行以下步骤:

ln -s /usr/local/include/freetype2 /usr/local/include/freetype

这样做可以避免在升级freetype2时重新创建符号链接的麻烦。

1
在使用“sudo easy_install PIL”之后,我遇到了这个问题,你的解决方案非常有效!谢谢! - spiralmoon
3
这也解决了在Yosemite上的问题。 - stevejpurves
我已经链接了freetype2,最好链接原始的版本,它在/usr/local/Cellar/freetype/2.5.5/include/freetype2。 - Salyangoz
1
@Salyangoz:/usr/local/include/freetype2 是指向 /usr/local/Cellar/freetype/2.5.5/include/freetype2 的符号链接(由 Homebrew 创建)。使用这个链接而不是实际路径的好处是,在升级时它仍然可以正常工作。 - mcuelenaere
2
我的 El Capitan 机器上没有安装 Freetype2,所以在创建此符号链接之前,我必须运行 brew install freetype - skandocious
我不得不执行 sudo ln -s /opt/local/include/freetype2 /opt/local/include/freetype 才能使其正常工作。 - Magnus

31

使用MacPorts,对我有效的解决方案:

sudo port install freetype
sudo ln -s /opt/local/include/freetype2 /opt/local/include/freetype

然后重新运行PIL构建过程。


当我升级到Maverick时,这对我起了作用,谢谢。 - Mo J. Mughrabi
在升级到Cocos2dx v3.3版本时,我在Yosemite操作系统上成功地使用了这个方法。 - andrewz

27

我用这个符号链接解决了这个问题:

ln -s /usr/local/Cellar/freetype/2.5.1/include/freetype2 /usr/local/include/freetype

我已经通过Homebrew安装了freetype。


5
这是由于freetype >= 2.1.5头文件的更改导致的。PIL没有使用正确的文档化方式来包含freetype头文件,这导致构建失败,因为freetype最终删除了包含头文件的过时方式。这个问题在http://freetype.sourceforge.net/freetype2/docs/tutorial/step1.html的顶部有记录:

注意:从FreeType 2.1.6开始,不再支持旧的头文件包含方案。这意味着,如果您像下面这样做,现在会出现错误:

#include <freetype/freetype.h>
#include <freetype/ftglyph.h>

请将此问题上报给PIL开发人员,并建议他们使用文档化的方法来包含freetype头文件:

#include <ft2build.h>
#include FT_ERRORS_H


4

经过多次尝试,我解决了这个问题,方法是编译PIL时不使用freetype支持。为此,我只需使用brew unlink freetype从$PATH中取消链接,然后使用pip install PIL==1.1.7即可。


Freetype是什么,到底是什么? :) - stantonk

3

3

我刚刚使用这篇Stackoverflow答案中提到的步骤解决了这个问题。看起来是Xcode在奇怪的位置安装了freetype,导致了问题。


2
在我的OSx操作系统中,我发现/opt/local/include/freetype2目录下有.h文件。因此,我输入以下命令:
sudo ln -s /opt/local/include/freetype2/ /usr/local/include/freetype

它可以正常工作。

也许最好的方法是将/opt/local/include添加到您的clang的包含路径中。


1

OSX Yosemite,这对我有用:

(virtualenv)

$ ln -s /opt/local/include/freetype2/ /usr/local/include/freetype2
$ pip install pil==1.1.7 --allow-external pil --allow-unverified pil

只运行了第一行,然后在 Yosemite 上这对我起作用了。能够 pip install PIL - Aaron Ash

0

我正在使用Arch Linux并遇到了这个问题。在我的情况下,我不得不手动从https://pypi.python.org/pypi/Pillow/2.2.1#downloads下载和解压缩zip文件。然后我编辑了文件_imagingft.c,将包含路径从freetype/fterrors.h更改为fterrors.h,因为在/usr/include/freetype2中没有freetype子目录,而fterrors.h位于其中。最后,python setup.py install正常工作。

编辑:我应该提到这是安装Pillow的解决方案,而不是PIL,但Pillow只是PIL的一个分支,它可能仍适用于其他遇到此问题的人。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接