简体   繁体   English

在 OS X Lion 上安装 PIL

[英]Installing PIL on OS X Lion

I am trying to install PIL on Mac OSX 10.7.4 but after several hours attempt couldn't succeed.我正在尝试在Mac OSX 10.7.4上安装 PIL,但经过几个小时的尝试无法成功。 All the time I have encountered the same problem provided detail in pastebin link below.我一直遇到同样的问题,在下面的 pastebin 链接中提供了详细信息。 Enlighten me!!开导我!!

Setting环境

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

Pastebin巴斯宾

I searched and tried from several sources:我从几个来源搜索并尝试过:

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 >>>

Edited as suggested by jdi but still running through the same problem as shown in above pastebin link按照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$

Further, I gave try with homebrew as suggested by the " the paul "此外,我按照“ 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

Here is the log of .pip这是.pip的日志

Its complaining about它抱怨

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

but stdarg.h file is there at the same location.stdarg.h文件位于同一位置。

I am not understanding why its trying to locate in MacOSX10.6.sdk as my current version of Lion is MacOSX10.7.sdk我不明白为什么它试图在MacOSX10.6.sdk中定位,因为我当前的 Lion 版本是MacOSX10.7.sdk

Getting crazy!!!变得疯狂!!!

If you are on Lion, using the newest XCode, then a potential problem for you is that they moved the location of the developer SDKs.如果您在 Lion 上使用最新的 XCode,那么对您来说潜在的问题是他们移动了开发人员 SDK 的位置。 Packages that expected them to live in /Developer/ would no longer find them as needed.期望它们存在于/Developer/中的软件包将不再根据需要找到它们。

Reference this article about specifics:具体参考这篇文章:
http://www.agile-workers.com/web/2012/03/qt-qmake-osx_sdk-xcode/ http://www.agile-workers.com/web/2012/03/qt-qmake-osx_sdk-xcode/

But in summary, what you might need to do is run:但总而言之,您可能需要做的是运行:
sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer
to point at the new location.指向新位置。

A manual fix might be to just symlink the SDK from /Applications/Xcode.app/Contents/Developer/... => /Developer/... , but I would first try the xcode-select tool.手动修复可能只是从/Applications/Xcode.app/Contents/Developer/... => /Developer/...符号链接 SDK,但我会先尝试 xcode-select 工具。

Update : Some more suggestions based on your new updates更新:基于您的新更新的更多建议

First off, I can't tell from what you posted whether PIL failed to build because of the SDK or not.首先,我无法从您发布的内容中判断 PIL 是否因为 SDK 而无法构建。 If it built successfully, and you are using the standard apple python, then chances are the homebrew python path is not in your own python path.如果它构建成功,并且您使用的是标准的苹果 python,那么自制 python 路径很可能不在您自己的 python 路径中。

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

If that still errors, then I suppose the issue is still related to missing SDK location.如果仍然错误,那么我认为问题仍然与缺少 SDK 位置有关。 You could symlink the new location of the SDK to the old one with:您可以将 SDK 的新位置符号链接到旧位置:

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

Or, you can try explicitly setting the the sdk path when you build pil:或者,您可以尝试在构建 pil 时显式设置 sdk 路径:

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

Easy solution:简单的解决方案:

  1. install Homebrew安装自制软件
  2. brew install pillow冲泡安装枕头

:) :)

如果您安装了Homebrew ,这将完成这项工作:

brew install pillow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM