在 Mac OS X 10.9 上使用 pip 安装 Python 图像库时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20325473/
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-18 20:12:22  来源:igfitidea点击:

Error installing Python Image Library using pip on Mac OS X 10.9

pythonmacospip

提问by Lukas Spie?

I want to install PIL on Mavericks using pip but get this error.

我想使用 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

My Command Line Tools are installed and up to date and every hint I found didn't help. How can I get this to compile?

我的命令行工具已安装并且是最新的,我发现的每个提示都没有帮助。我怎样才能编译这个?

EDIT: I just checked, freetype is also already installed via homebrew

编辑:我刚刚检查过,freetype 也已经通过自制软件安装了

采纳答案by mcuelenaere

Instead of symlinking to a specific version of freetype2, do this:

不要符号链接到特定版本的 freetype2,而是这样做:

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

This saves you the trouble of recreating the symlink whenever you upgrade freetype2.

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

回答by Lukas Spie?

I just solved this using the steps described in thisStackoverflow answer. Seems this is Xcode's fault for installing freetype in strange locations.

我刚刚使用Stackoverflow 答案中描述的步骤解决了这个问题。似乎这是 Xcode 在奇怪位置安装 freetype 的错误。

回答by Dmitry Akinin

I've solved this problem with this symlink:

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

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

I have freetype already installed via homebrew too.

我也已经通过自制软件安装了 freetype。

回答by Mike Fogel

With macports, the solution that worked for me:

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

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

And then re-run the PIL build process.

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

回答by Beau

I'm using Arch Linux and had this issue. In my case had to manually download and unpack the zip file from https://pypi.python.org/pypi/Pillow/2.2.1#downloads. I then edited the file _imagingft.cto change the include path from freetype/fterrors.hto fterrors.has there was no freetypesubdirectory of /usr/include/freetype2where fterrors.hwas located. Finally python setup.py installworked fine.

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

Edit: I should mention this was the solution for installing Pillow, not PIL, but Pillow is just a fork of PIL and it may still be applicable to others with this issue.

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

回答by neverpanic

This is caused by a change in the headers of freetype >= 2.1.5. PIL is not using the correct documented way to include the freetype headers, which causes the build to fail now that freetype finally removed the long-deprecated way of including the headers. This problem is documented right at the top of http://freetype.sourceforge.net/freetype2/docs/tutorial/step1.html:

这是由 freetype >= 2.1.5 的标头更改引起的。PIL 没有使用正确记录的方式来包含 freetype 标头,这导致构建失败,因为 freetype 最终删除了长期不推荐使用的包含标头的方式。这个问题记录在http://freetype.sourceforge.net/freetype2/docs/tutorial/step1.html的顶部:

NOTE: Starting with FreeType 2.1.6, the old header file inclusion scheme is no longer supported. This means that you now get an error if you do something like the following:

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

注意:从 FreeType 2.1.6 开始,不再支持旧的头文件包含方案。这意味着如果您执行以下操作,您现在会收到错误消息:

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

Please take this problem upstream to the developers of PIL and advise them to use the documented way of including freetype headers:

请将这个问题向上级提交给 PIL 的开发人员,并建议他们使用包含 freetype 标头的文档化方式:

#include <ft2build.h>
#include FT_ERRORS_H

#include <ft2build.h>
#include FT_ERRORS_H

回答by blowyourheart

In my OSx, I found the .hfile in /opt/local/include/freetype2direcoty. So, I type

在我的 OSx 中,我直接找到了该.h文件/opt/local/include/freetype2。所以,我输入

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

it works

有用

Maybe the best way is to add /opt/local/includeto your clang's include path.

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

回答by diegofleury

After many attempts, I solved this problem compiling the PIL without freetype support. To do that, I simply unlinked from my $PATH using brew unlink freetypeand then, pip install PIL==1.1.7.

经过多次尝试,我在没有freetype支持的情况下编译PIL解决了这个问题。要做到这一点,我只是使用brew unlink freetype,然后从 $PATH 取消链接pip install PIL==1.1.7

回答by aclark

Use Pillowwhere this issue is fixed "for real":

在“真正”修复此问题的地方使用Pillow

And where you can report issues and see them addressed in a timely fashion:

您可以在哪里报告问题并及时解决问题:

回答by volvox

If you're still looking for answers like I was after reading this and other googling, you may be interested to see this:

如果您在阅读本文和其他谷歌搜索后仍在寻找答案,您可能有兴趣查看以下内容:

Warning

警告

Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead.

Pillow >= 2.1.0 不再支持“import _imaging”。请改用“from PIL.Image import core as _imaging”。

from here

这里

By the time you read this, the page will probably have changed, but the text will be still here at least.

当您阅读本文时,页面可能已更改,但文本至少会保留在此处。