Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to access a shared C library in Python with ctypes on Mac OS X 10.6.8 with Python 2.7.4. To do this, I need to #include <Python.h> in my C code. If I try to compile a C script that only has that one include statement in it, call 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'm running Mac 10.6, I have Xcode 3.2.6, the latest version available on this iteration of OS X without paying to upgrade to 10.7 and getting Xcode 4. Is there a way to get the Python header file without upgrading my OS?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

Python is a framework on Mac OS X so you need to,

#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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...