无法在Mac OS X 10.9之后安装PIL

132

我刚刚将我的Mac OS更新到了10.9,发现一些(全部?)Python模块不见了,特别是 Image 模块。

我尝试执行 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版本,这可能是原因吗?


不是答案,但你尝试过Pillow吗?https://pypi.python.org/pypi/Pillow/2.2.1 - 它是一个非常好的PIL支持库。 - James Addison
4
Pillow 2.2.1 同样受到影响。 - Adam J. Forster
你需要执行 pip install pillow - kilojoules
在macOS 10.10.5 Yosemite上,pip install Pillow==5.0.0可以正常工作,并安装了.../site-packages/PIL。 (为什么是5.0.0?请参见问题。) - denis
28个回答

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即可解决该问题。

2

我不想安装XCode(不常用),也不想在应用程序目录上操作。我从本帖子中的许多答案中借鉴,以下两个步骤对我在10.9.5上有效:

sudo easy_install pip
sudo pip install pillow

我觉得很奇怪,我必须使用easy_install来安装pip。但在重新安装之前,pip不愿意为我工作。


2

请确保您的xcode已安装命令行工具。然后执行:

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

我能够使用 Mavericks 版本的 Xcode 安装它,而无需使用命令行工具。 - radtek

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

brew tap Homebrew/python
brew install pillow

你好rchapman。当我运行brew来安装samueljohn/python/pillow时,它会给出一个警告:pillow-2.5.1已经安装,只是没有链接。在此之前,有15个警告,如:无法在samueljohn/python/cpyrit-cuda上安装homebrew/python/cpyrit-cuda。这是为什么呢?或者我该如何链接pillow? - 0xmtn

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

1

找到了解决方案...你需要这样建立符号链接 ln -s /opt/X11/include/X11 /usr/local/include/X11 然后 sudo pip install pil 应该就可以工作了。


对我没用...你在让它工作之前更新了你的Xcode吗?你重启了你的Mac很多次吗?这让我感到沮丧。唉。 - bonbon.langes
我之前更新了我的Xcode,并重新启动了我的Mac,即使我不确定这是否有帮助。也许你的X11路径与我的不同。可以尝试其他一些答案。 - Vincent Audebert

1
执行以下命令行。 在Mac OS 10.9.5上运行得很好。
easy_install pip sudo pip install setuptools --no-use-wheel --upgrade sudo pip install Pillow
祝好, Theo

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/

1
两周前已经有类似的答案被给出并被接受了,我看不出你的回答有什么额外的价值。 - Soravux
这个答案与被接受的答案不同。我将此版本作为评论添加到被接受的答案中。命令是 sudo 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 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/X11 - Sergey Orshanskiy

0
sudo pip uninstall pillow
pip install pillow

对我来说起作用了。我在Yosemite上运行Python 2.7.9。import PIL现在对我有效。


0

试试这个:

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

3
请再加入一些内容,并解释为什么他应该这样做。 - Sir l33tname

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