开发者

Cross-platform method for finding python include folder

开发者 https://www.devze.com 2023-02-23 04:17 出处:网络
I have python extension code that I need to cross-platform compile, and to do so, I need to be able to find the python include folder.On Linux and Mac OSX, I can do python-config --include and it give

I have python extension code that I need to cross-platform compile, and to do so, I need to be able to find the python include folder. On Linux and Mac OSX, I can do python-config --include and it gives me something like -I/Library/Frameworks/Python.framework/Versions/6.3/include/python2.6. This is fine and dandy, except that my Windows python distro doesn't have python-config. Is there a开发者_运维技巧n easy way, through python code, of finding where it thinks the include folder is? For numpy, this snippet does the job:

try:
    numpy_include = numpy.get_include()
except AttributeError:
    numpy_include = numpy.get_numpy_include()

Is there an analogous method for the python include folder?


You can try this:

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

Note: I found this out by looking at python-config source.

0

精彩评论

暂无评论...
验证码 换一张
取 消