5

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

环境

tbc:~ mystic$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/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 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

变得疯狂!!!

4

3 回答 3

9

如果您在 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/...=>符号链接 SDK /Developer/...,但我会首先尝试 xcode-select 工具。

更新:基于您的新更新的更多建议

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

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

如果仍然错误,那么我认为问题仍然与缺少 SDK 位置有关。您可以将 SDK 的新位置符号链接到旧位置:

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
于 2012-05-18T20:05:05.380 回答
1

简单的解决方案:

  1. 安装自制软件
  2. 冲泡安装枕头

:)

于 2012-05-18T19:32:11.107 回答
0

If you have Homebrew installed, this will do the the job:

brew install pillow
于 2017-02-04T11:23:37.923 回答