132

我刚刚将我的 Mac OS 更新到 10.9,我发现我的一些(全部?)Python 模块不再存在,尤其是图像模块。

所以我尝试执行sudo pip install pil,但我收到此错误:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found

#      include <X11/Xlib.h>

               ^

1 error generated.

error: command 'cc' failed with exit status 1

我的 Xcode 是最新的,我不知道。PIL 是否可能不兼容 10.9?

4

28 回答 28

211

以下为我工作:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
sudo pip install pil

更新:

但是下面有更正确的解决方案,由 Will 提供。

打开你的终端并执行: xcode-select --install

于 2013-10-23T15:05:07.143 回答
102

打开你的终端并执行:

xcode-select --install

于 2013-11-06T16:44:34.930 回答
34
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/ /usr/local/include/X11

对我有帮助!操作系统 x 10.9

pip install pillow

但!pip安装后...

*** ZLIB (PNG/ZIP) support not available

最后我通过运行修复它:

xcode-select --install

然后重新安装枕头

pip install pillow

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.2.1
    platform     darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
                 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
    --------------------------------------------------------------------
    --- TKINTER support available
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    --- TIFF G3/G4 (experimental) support available
    --- FREETYPE2 support available
    --- LITTLECMS support available
    --- WEBP support available
    --- WEBPMUX support available
    --------------------------------------------------------------------
于 2013-10-23T20:00:53.563 回答
14

为我工作(OS X Yosemite 10.10.2 - Python 2.7.9):

xcode-select --install
sudo pip install pillow

试试这个来检查它:

from PIL import Image
image = Image.open("file.jpg")
image.show()
于 2015-04-03T18:59:26.980 回答
11

这就是我所做的,某些步骤可能仅对 PIL 不是必需的,但无论如何我需要 libpng 和其他步骤:

1) 运行 xcode install,使用此命令或从应用商店下载更新:

xcode-select --install

1b) 添加命令行工具可选工具,在 Mountain Lion 中,这是 xcode 下载页面上的一个选项,但现在您必须使用您的 Apple id 注册并从以下位置下载:https ://developer.apple.com/downloads/

寻找 Xcode 的命令行工具(OS X Mavericks)

2)安装python所需的一切(使用brew),我相信你也可以使用port:

brew install readline sqlite gdbm
brew install python --universal --framework 
brew install libpng jpeg freetype

如果需要,即如果升级,则取消链接/重新链接。

3)安装Pip和所需模块:

easy_install pip 
sudo pip install setuptools --no-use-wheel --upgrade

4)最后这没有错误:

sudo pip install Pillow

更新11/04/14:PIL repo 不再接收更新或支持,因此应使用 Pillow。现在不推荐使用以下内容,因此请坚持使用 Pillow。

sudo pip install pil --allow-external pil --allow-unverified pil

更新(旧):安装 Pillow(PIL 前叉)时同样适用,应该提到它在大多数 PIL 情况下迅速成为替代品。不要在第 4 步中安装 pip,而是运行以下命令:

sudo pip install Pillow

希望这对某人有帮助!

于 2014-07-18T13:22:40.837 回答
9

安装命令行工具为我解决了这个问题

您必须单独安装它们,因为它们现在不是 xcode 中软件包的一部分:

https://developer.apple.com/downloads/index.action?=command%20line%20tools#

于 2013-10-24T15:18:22.697 回答
8

没有一个对我有用..我一直收到:

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1

因此,我找到了使用以下解决方案的解决方法:

sudo export CFLAGS=-Qunused-arguments
sudo export CPPFLAGS=-Qunused-arguments
sudo pip install PIL --allow-external PIL --allow-unverified PIL

这样我就可以安装了。

于 2014-04-26T21:14:04.563 回答
6

我有一个类似的问题:安装枕头失败clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future],安装命令行工具失败Can't install the software because it is not currently available from the Software Update server.,甚至手动安装命令行工具后,PIL的编译失败。

发生这种情况是因为最新版本的 xcode 下的 clang 不会对未知的编译器标志发出警告,而是会以硬错误停止编译。

要解决此问题,只需export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"在尝试编译(安装 pil)之前在终端上运行。

于 2014-03-25T08:52:30.767 回答
5

只需运行

pip install pil --allow-external pil --allow-unverified pil

于 2014-02-12T03:52:56.510 回答
3

这是我在 mac os 10.9.1 上的步骤

1. sudo su
2. easy_install pip
3. xcode-select --install
4. pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
于 2014-03-05T16:25:30.217 回答
2

我遇到以下错误

building 'PIL._imagingft' extension
_imagingft.c:62:10: fatal error: 'freetype/fterrors.h' file not found

#include <freetype/fterrors.h>

         ^

1 error generated.

error: command 'cc' failed with exit status 1

解决方案是将 freetype2 符号链接到 freetype,这解决了问题。

于 2014-06-12T07:44:21.187 回答
2

确保在 xcode 上安装了命令行工具。然后执行:

sudo pip install pil --allow-external pil --allow-unverified pil
于 2014-05-16T03:00:10.020 回答
2

您可以使用 Homebrew 进行安装 http://brew.sh

brew tap Homebrew/python
brew install pillow
于 2014-03-14T05:14:05.480 回答
2

我不想安装 XCode(我不使用它)而且我不愿意摆弄 Application 目录。我从这篇文章中的许多答案中抄袭下来,以下两个步骤适用于 10.9.5:

sudo easy_install pip
sudo pip install pillow

在我看来,我必须使用 easy_install 来安装 pip 确实很奇怪。但是在(重新)安装之前,pip 不想为我工作。

于 2015-01-09T03:14:11.553 回答
1

重用@DmitryDemidenko 的答案就是它对我的工作方式:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11

接着

sudo pip install -U PIL --allow-external PIL --allow-unverified PIL
于 2014-02-03T14:14:04.277 回答
1

找到了解决方案......你必须像这样对 X11 进行符号链接ln -s /opt/X11/include/X11 /usr/local/include/X11,然后sudo pip install pil应该可以工作。

于 2013-10-23T03:47:52.747 回答
1

执行下面的命令行。在 Mac OS 10.9.5 上像魅力一样工作

easy_install pip

sudo pip install setuptools --no-use-wheel --upgrade

sudo pip install Pillow

最好的,西奥

于 2015-03-26T15:32:55.467 回答
0

改为安装枕头:

sudo pip install pillow
于 2014-07-08T18:25:10.833 回答
0

我最近从 OS 10.8 -> 10.9 升级的机器卡在 xcrun 和 lipo 之间的循环中。

将 /usr/bin/lipo 重命名为 /usr/bin/lipo_broken

有关如何解决的更多信息,请参阅此线程:

xcrun/lipo 在 OS X Mavericks 和 XCode 4.x 中冻结

于 2014-06-30T15:54:04.803 回答
0

由于公认的答案是正确的,xcode-select --install但有些人(包括我)可能会遇到Can't install the software because it is not currently available from the Software Update server 如果您使用的是 beta 软件(因为我现在使用的是 Yosemite 并且遇到了同样的问题),您需要单独获取 CLT,因为它不包含在XCode(甚至是 xcode beta)前往 developers.apple.com 并为您的操作系统获取 CLT 工具;)

PS 你不需要 XQuartz 来让 PIL 或 Pillow 工作

于 2014-06-29T16:06:12.260 回答
0

更完整的解决方案需要安装 Xquartz X11 子系统,该子系统已经在 Apple 之外构建了几年。这是我用来完成所有工作的步骤

  1. 从http://xquartz.macosforge.org/landing/安装 XQuartz
  2. sudo pip install pillow
于 2014-04-08T19:09:38.707 回答
0
ln -s /usr/local/include/freetype2 /usr/local/include/freetype
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pil
于 2014-09-16T21:00:09.723 回答
0

尝试这个:

ln -s /usr/local/include/freetype2 /usr/local/include/freetype
于 2014-10-22T17:11:42.160 回答
0
sudo pip uninstall pillow
pip install pillow

为我工作。我在 Yosemite 上运行 Python 2.7.9。import PIL现在为我工作。

于 2015-03-25T07:57:06.073 回答
0

这就是我所做的:

首先升级到 Xcode 5(我正在运行 10.9)。然后,在终端中执行以下命令:

$ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
$ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 usr/include/
于 2013-11-06T04:39:03.077 回答
0

在 Mac OSC 10.10 Yosemite 上安装 PIL (Imaging.1.1.7)。我尝试了这里推荐的许多修复,但每一个都遇到了麻烦。我终于通过编辑 setup.py 文件解决了这个问题:

TCL_ROOT = "/opt/X11/include"

它在 _imagingtk.c 的编译中传递了 X11 的适当包含路径,这对我来说是个问题。更改后立即工作。

于 2015-04-18T18:27:08.453 回答
0

我已经搬到pyenvvirtualenv,这解决了我的问题。

于 2017-11-12T22:01:54.663 回答
-4
  1. ln -s /opt/X11/include/X11 /usr/local/include/X11
  2. pip install pil 没有 sudo
于 2013-10-23T09:38:37.730 回答