Missing Python.h header file on Mac OS X 10.6

I am trying to access the C shared library in Python using ctypes on Mac OS X 10.6.8 using Python 2.7.4. To do this, I need #include <Python.h> in my C code. If I try to compile a C script that only has this include statement, name it "sample.c", I get:

 $ gcc -shared -o sample.so sample.c sample.c:1:20: error: Python.h: No such file or directory 

Since I am running Mac 10.6, I have Xcode 3.2.6, the latest version is available on this iteration of OS X without paying upgrade to 10.7 and getting Xcode 4. Is there a way to get the Python header file without updating my OS?

+4
source share
2 answers

Python is the foundation for Mac OS X, so you need

 #include <Python/Python.h> 

You also need to call gcc with the -framework argument to actually do anything inside C,

 gcc -shared -o sample.so sample.c -framework Python 
+17
source

I'm not sure about 10.6.8, but Python.h should be in

 /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 

if you installed the official python.org binary. Try to add

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

into the gcc command and see if this works.

+1
source

Source: https://habr.com/ru/post/1479848/


All Articles