我在setup.py
中指定了以下include_dirs
和library_dirs
:
/opt/x86_64-sdk-linux/usr/bin/python3 setup.py build_ext \
--include-dirs=/opt/neon-poky-linux-gnueabi/usr/include/python3.5m/ \
--library-dirs=/opt/neon-poky-linux-gnueabi/usr/lib/ \
--rpath=/opt/neon-poky-linux-gnueabi/usr/lib/ \
--plat-name=linux_armv7l
但是,生成的gcc命令(在执行python3 setup.py build_ext
时)还包括运行python3
的include路径(为了可读性,我添加了换行符):
arm-poky-linux-gnueabi-gcc \
--sysroot=/opt/neon-poky-linux-gnueabi \
-I. \
-I/opt/neon-poky-linux-gnueabi/usr/include/python3.5m/ \
-I/opt/x86_64-sdk-linux/usr/include/python3.5m \
-c py/constraint.cpp -o build/temp.linux-x86_64-3.5/py/constraint.o
第三个包含路径未显式指定,但在编译时仍在使用。
我该如何确保只使用我指定的include-dirs
?
发布于 2018-07-26 03:41:57
您将需要覆盖build_ext
命令,因为the stdlib's build_ext
ensures the Python header files, both platform specific and not, are always appended to the include paths。
以下是自定义build_ext
命令的示例,该命令在最终确定选项后清理包含路径:
# setup.py
from distutils import sysconfig
from setuptools import setup
from setuptools.command.build_ext import build_ext as build_ext_orig
class build_ext(build_ext_orig):
def finalize_options(self):
super().finalize_options()
py_include = sysconfig.get_python_inc()
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
for path in (py_include, plat_py_include, ):
for _ in range(self.include_dirs.count(path)):
self.include_dirs.remove(path)
setup(
...,
cmdclass={'build_ext': build_ext},
)
更新
库目录的方法相同:当选项最终确定时,清除列表:
class build_ext(build_ext_orig):
def finalize_options(self):
super().finalize_options()
...
libdir = sysconfig.get_config_var('LIBDIR')
for _ in range(self.library_dirs.count(libdir)):
self.library_dirs.remove(libdir)
https://stackoverflow.com/questions/51522248
复制相似问题