2011-04-10 64 views
2

我有需要跨平臺編譯的python擴展代碼,爲此,我需要能夠找到python include文件夾。在Linux和Mac OSX上,我可以做python-config --include,它給了我一些像-I/Library/Frameworks/Python.framework/Versions/6.3/include/python2.6。這是好的和丹迪,除了我的Windows python發行版沒有。有沒有一種簡單的方法,通過Python代碼找到它認爲包含文件夾的位置?對於numpy,這個片段做這項工作:查找python包含文件夾的跨平臺方法

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

是否有蟒蛇類似的方法,包括文件夾?

+0

我不認爲有什麼方法可以找到實際的包含文件夾。我認爲你只需要看看python-config是否存在,如果不能用你能想到的許多不同的路徑名猜測:|。 – JackMc 2011-04-10 19:47:05

回答

4

你可以試試這個:

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

注:我發現了這一點,通過觀察來源。

+0

在Python 2.7和3.2中,'sysconfig'已被擴展並擴展到標準庫中的自己的模塊,獨立於'distutils':http://docs.python.org/library/sysconfig.html,例如, 'sysconfig.get_path( '包括')' – 2011-04-10 19:58:37

相關問題