在Mac OS X 10.6上缺少Python.h头文件 [英] Python.h header file missing on Mac OS X 10.6
问题描述
我正在尝试使用Python 2.7.4在Mac OS X 10.6.8上使用ctypes
在Python中访问共享的C库.为此,我需要在我的C代码中#include <Python.h>
.如果我尝试编译仅包含一个include语句的C脚本,则将其称为"sample.c",我将得到:
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
因为我运行的是Mac 10.6,所以我拥有Xcode 3.2.6,这是OS X迭代中可用的最新版本,而无需付费升级到10.7并获取Xcode 4.升级我的操作系统?
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?
推荐答案
Python是Mac OS X上的框架,因此您需要
Python is a framework on Mac OS X so you need to,
#include <Python/Python.h>
您还需要使用-framework
参数调用gcc
,以在C中实际执行任何操作,
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
这篇关于在Mac OS X 10.6上缺少Python.h头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!