如何在OS X Mountain Lion上构建PIL?

时间:2012-08-29 14:25:24

标签: python macos python-imaging-library osx-mountain-lion

当我尝试在Mac OS X 10.8.1 Mountain Lion上构建PIL时,我得到以下结果:

$ sudo python setup.py install
Password:
running install
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imaging' extension
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBJPEG -DHAVE_LIBZ -IlibImaging -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.8-intel-2.7/_imaging.o
clang: warning: argument unused during compilation: '-mno-fused-madd'
_imaging.c:75:10: fatal error: 'Python.h' file not found
#include "Python.h"
         ^
1 error generated.
error: command 'clang' failed with exit status 1

2 个答案:

答案 0 :(得分:5)

PIL无法跟上对新操作系统的支持(通过对新的lib目录进行setup.py更改等)。但是除了PIL之外,你可以使用“友好的PIL叉” Pillow

如果您收到同样的错误,请报告问题:

答案 1 :(得分:0)

this SO question,我能够在/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7中找到Python.h。 (注意我已经安装了Xcode)

然后我跑了sudo python setup.py build_ext --include-dirs /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7:/Developer/SDKs/MacOSX10.7.sdk/usr/include

(注意:/Developer/SDKs/MacOSX10.7.sdk/usr/include已添加,因为Python.h解析后缺少stdio.h)

最后,我跑了sudo python setup.py install