python - 在 OS X Lion 上安装 PIL

标签 python osx-lion python-imaging-library

我正在尝试在 Mac OSX 10.7.4 上安装 PIL,但几个小时后尝试无法成功。我一直遇到同样的问题,在下面的 pastebin 链接中提供了详细信息。开导我!!

设置

tbc:~ mystic$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

Pastebin

我从几个来源进行了搜索和尝试:

Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Image
>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL
>>>

按照 jdi 的建议进行编辑,但仍然遇到与上述 pastebin 链接中所示相同的问题

tbc:jpeg-8c mystic$ xcode-select -version
xcode-select version 2003.
tbc:jpeg-8c mystic$ which xcode-select
/usr/bin/xcode-select
tbc:jpeg-8c mystic$ xcode-select -print-path
/Applications/Xcode.app/Contents/Developer
tbc:jpeg-8c mystic$

此外,我按照“the paul”的建议尝试使用自制软件

tbc:cellar mystic$ brew link jpeg
Linking /usr/local/Cellar/jpeg/8d... 3 symlinks created
tbc:cellar mystic$ brew install pil
Error: pil-1.1.7 already installed
tbc:cellar mystic$ brew uninstall pil
Uninstalling /usr/local/Cellar/pil/1.1.7...
tbc:cellar mystic$ brew install pil
==> Downloading http://effbot.org/downloads/Imaging-1.1.7.tar.gz
Already downloaded: /Library/Caches/Homebrew/pil-1.1.7.tar.gz
==> python setup.py build_ext
==> python setup.py install --prefix=/usr/local/Cellar/pil/1.1.7
==> Caveats
This formula installs PIL against whatever Python is first in your path.
This Python needs to have either setuptools or distribute installed or
the build will fail.
Warning: Non-executables were installed to "bin".
Installing non-executables to "bin" is bad practice.
The offending files are:
/usr/local/Cellar/pil/1.1.7/bin/pilfont.py
==> Summary
/usr/local/Cellar/pil/1.1.7: 174 files, 2.0M, built in 15 seconds
tbc:cellar mystic$ python 
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pil
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pil
>>> from PIL import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL

这是.pip的日志

它在提示

/Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory

但是 stdarg.h 文件在同一位置。

我不明白为什么它试图在 MacOSX10.6.sdk 中定位,因为我当前的 Lion 版本是 MacOSX10.7.sdk

快疯了!!!

最佳答案

如果您在 Lion 上使用最新的 XCode,那么对您来说一个潜在的问题是他们移动了开发者 SDK 的位置。希望它们位于 /Developer/ 中的包将不再根据需要找到它们。

具体引用这篇文章:
http://www.agile-workers.com/web/2012/03/qt-qmake-osx_sdk-xcode/

但总而言之,您可能需要做的是运行:
sudo/usr/bin/xcode-select -switch/Applications/Xcode.app/Contents/Developer
指向新位置。

手动修复可能只是从 /Applications/Xcode.app/Contents/Developer/... => /Developer/... 符号链接(symbolic link) SDK ,但我会先尝试 xcode-select 工具。

更新:根据您的新更新提出更多建议

首先,我无法从您发布的内容中判断 PIL 是否由于 SDK 的原因而无法构建。如果构建成功,并且您使用的是标准的 apple python,那么自制 python 路径很可能不在您自己的 python 路径中。

$ python
>>> import sys
>>> sys.path.append("/usr/local/lib/python2.7/site-packages")
>>> from PIL import Image

如果仍然出错,那么我想问题仍然与缺少 SDK 位置有关。 您可以通过以下方式将 SDK 的新位置符号链接(symbolic link)到旧位置:

mkdir -p -v /Developer/SDKs
ln -s /Applications/Xcode.app/Contents/Developer/MacOSX10.6.sdk  /Developer/SDKs/MacOSX10.6.sdk

或者,您可以尝试在构建 pil 时显式设置 sdk 路径:

brew remove pil
export SDKROOT=/Applications/Xcode.app/Contents/Developer/MacOSX10.6.sdk
brew install pil

关于python - 在 OS X Lion 上安装 PIL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10657363/

相关文章:

python - 从 POST 解码 base64 以在 PIL 中使用

Python在JPEG图像上找到黑色方 block 的坐标

python - 为什么 setattr 对属性和方法的作用不同?

python - 导出MySql时如何删除索引和触发器?

python - 一元二次方程的错误解

xcode - Mac OS X Lion : can not install mysql-python 上缺少 llvm-gcc

python - 升级到 Lion 后如何让 virtualenv 工作?

cocoa - NSWorkspace launchApplicationAtURL 不适用于 NSWorkspaceLaunchConfigurationArguments

Python正则表达式通过带有一个前导空格的特殊字符截断字符串

python - Linux Mint Cinnamon 错误打开设置(没有名为 'PIL' 的模块)