简体   繁体   中英

How do I build PIL on OS X Mountain Lion?

When I try to build PIL on Mac OS X 10.8.1 Mountain Lion, I get the following result:

$ 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

PIL does not keep up with support for new operating systems (by making changes to setup.py for new lib dirs, etc). But intstead of PIL, you can use the "friendly PIL fork" Pillow :

And if you get the same error, please report the issue:

From this SO question , I was able to find Python.h in /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7. (note that i have Xcode installed)

I then ran 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

(note: /Developer/SDKs/MacOSX10.7.sdk/usr/include added because stdio.h was missing once the Python.h was resolved)

Finally, I ran sudo python setup.py install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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