查找python包含文件夹的跨平台方法

查找python包含文件夹的跨平台方法,python,Python,我有需要跨平台编译的python扩展代码,为此,我需要能够找到PythonInclude文件夹。在Linux和Mac OSX上,我可以做python配置--include,它给了我类似-I/Library/Frameworks/python.framework/Versions/6.3/include/python2.6的东西。除了我的Windows python发行版没有python配置之外,这一切都很好。有没有一种简单的方法可以通过python代码找到它认为包含文件夹的位置?对于numpy,

我有需要跨平台编译的python扩展代码,为此,我需要能够找到PythonInclude文件夹。在Linux和Mac OSX上,我可以做
python配置--include
,它给了我类似
-I/Library/Frameworks/python.framework/Versions/6.3/include/python2.6
的东西。除了我的Windows python发行版没有
python配置
之外,这一切都很好。有没有一种简单的方法可以通过python代码找到它认为包含文件夹的位置?对于
numpy
,此代码段执行以下任务:

try:
    numpy_include = numpy.get_include()
except AttributeError:
    numpy_include = numpy.get_numpy_include()
python包含文件夹有类似的方法吗?

您可以尝试以下方法:

>>> from distutils import sysconfig
>>> sysconfig.get_python_inc()
'/usr/include/python2.6'
>>> sysconfig.get_python_inc(plat_specific=True)
'/usr/include/python2.6'

注意:我通过查看
python config
源代码找到了这个问题。

我认为没有任何方法可以找到实际的include文件夹。我想你只需要看看python配置是否存在,如果不使用你能想到的那么多不同的路径名进行猜测:|。在python 2.7和3.2中,
sysconfig
已经扩展并通用到标准库中自己的模块中,独立于
distutils
:,例如,
sysconfig.get\u path(“包括”)