Search code examples
pythonmacosclangsetuptoolseasy-install

Changing Python easy_install's default include path


Question about Python's setuptools. I just did a fresh install of Mac OS 10.8 and installed the official Python 2.7.3 package. When installing the binary module py-bcrypt (or any other binary module for that matter), I get the following error:

bcrypt/bcrypt_python.c:17:10: fatal error: 'Python.h' file not found
#include "Python.h"
         ^
1 error generated.
error: Setup script exited with error: command 'clang' failed with exit status 1

Running sudo easy_install --verbose py-bcrypt shows the following call to CLang:

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 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c bcrypt/bcrypt_python.c -o build/temp.macosx-10.8-intel-2.7/bcrypt/bcrypt_python.o

...which is fine except for this part:

-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 

Because Python.h is actually stored in the non-System Library here: /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h

So to finally get to the point: How do you change the default include path used by setuptools?


Solution

  • In Ubuntu, doing this in .bashrc or .zshrc would solve the issue:

    export C_INCLUDE_PATH=/you_name_it/include/python2.7
    export CPLUS_INCLUDE_PATH=/you_name_it/include/python2.7
    

    It enabled gcc to find other headers you need, but I'm not sure whether it works for clang.