Python安装脚本扩展,你如何包含.h文件?

use*_*133 10 c python installation setup.py

所以我有一个看起来像这样的目录:

 home\
     setup.py
     some_python_file.py
     ext\
         __init__.py
         c_file1.c
         c_file2.c
         ext_header.h
Run Code Online (Sandbox Code Playgroud)

显然,头文件是编译c文件所必需的,但问题是我无法让安装脚本包含头文件.

我的扩展对象是这样的:

Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c'])
Run Code Online (Sandbox Code Playgroud)

哪个有效,但不包括头文件.如果我将其更改为:

Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c', 'ext_header.h'])
Run Code Online (Sandbox Code Playgroud)

它包含'.h'文件,但在运行install时不会构建.相反,它给出了错误error: unknown file type '.h' (from 'ext/ext_header.h')

如果我将头文件包含为这样的数据文件:

data_files=[('ext', ['ext/ext_header.h'])]
Run Code Online (Sandbox Code Playgroud)

它根本不起作用,.h文件甚至没有进入MANIFEST文件.

所以我的问题是,你如何将这个扩展包含在头文件中以便python setup.py install正确构建它?

use*_*133 8

我有一种感觉pyfunc正在寻找更标准的解决方案,但我确实找到了另一种解决方案.我不知道这是一个好的解决方案还是只是一个黑客,但我所做的只是将头文件添加到MANIFEST.in.文档并没有真正让它看起来像是MANIFEST.in文件的用途,但它确实有效.我的MANIFEST.in文件现在看起来像这样:

include ext/ext_header.h
Run Code Online (Sandbox Code Playgroud)

其中包括文件并在我运行时成功编译 python setup.py install