【发布时间】:2018-02-16 11:47:49
【问题描述】:
在尝试使基于 scons 的构建系统尽可能独立于平台时,我想知道以下几点:
为什么python2返回包含路径/usr/local/include/python2.7?该路径不包含Python.h,如果我依赖该路径,构建将失败。
python2
在 python2 中使用 sysconfig:
$ /usr/bin/python2
Python 2.7.13 (default, Nov 23 2017, 15:37:09)
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_path('include')
'/usr/local/include/python2.7'
给/usr/local/include/python2.7。这是一个空文件夹。
从 shell 调用 python2-config:
$ /usr/bin/python2-config --includes
-I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7
这给出了不同的路径。我能够在/usr/include/python2.7 中找到Python.h。
python3
在 python3 中使用 sysconfig:
$ /usr/bin/python3
Python 3.5.3 (default, Nov 23 2017, 11:34:05)
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_path('include')
'/usr/include/python3.5m'
从 shell 调用 python3-config:
/usr/bin/python3-config --includes
-I/usr/include/python3.5m -I/usr/include/python3.5m
得到的路径/usr/include/python3.5m 与小船进近相同。 Python.h 位于此处。
蟒蛇
如果我使用 anaconda python(2 或 3),路径也是一致的(与 python3 一样)。
我已经找到了一些解决方法,例如在usr/local/include 中放置一个指向usr/include 的软链接,或者只是丢弃路径中的local/,但两者看起来都不是一个好的解决方案。
编辑:
目前,python2 中不正确的包含路径使我的构建系统不像我想要的那样独立于平台。如果使用 python2,添加(可选)环境变量 PYTHON_INCLUDE_PATH 可以让我定义正确的路径。但是始终返回正确路径的解决方案会对我有很大帮助(在 python 端或使用 scons 特定的功能)。
因为我的构建系统是基于 scons a
【问题讨论】:
-
为什么 scons 被标记?
-
我的构建系统是基于 scons 的。如果有(特定于 scons 的)方法来获取正确的包含路径,这也会有很大帮助。
-
什么版本的 SCons 以及你使用哪个版本的 python 运行它?如果您需要帮助,请发布您的相关 SCons 逻辑 (SConstruct/SConscript)..
-
真正让我困惑的是上面描述的 python2-config 与 sysconfig.get_path('include') 的奇怪行为。如果有一个 scons 特定的方法来规避这个问题,它也可以解决我的问题,但它并没有真正回答这个问题。所以你是对的,scons 标签有点误导。明天我将打开另一个更具体的问题。感谢您迄今为止的帮助!
-
感谢 Jeff 的回答,不再需要 scons 特定的解决方案。谢谢!
标签: python-3.x python-2.7 include-path