Python 设置脚本扩展,如何包含 .h 文件?
所以我有一个看起来像这样的目录:
home\
setup.py
some_python_file.py
ext\
__init__.py
c_file1.c
c_file2.c
ext_header.h
显然头文件是编译 c 文件所必需的,但问题是我无法让安装脚本包含头文件。
我的扩展对象是这样的:
Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c'])
它可以工作,但不包括头文件。如果我将其更改为:
Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c', 'ext_header.h'])
它包含“.h”文件,但当我运行安装时不会构建。相反,它给出错误错误:未知文件类型'.h'(来自'ext/ext_header.h')
如果我将头文件作为数据文件包含在内:
data_files=[('ext', ['ext/ext_header.h'])]
它不起作用总之,.h 文件甚至没有进入 MANIFEST 文件。
所以我的问题是,如何将此扩展包含在头文件中,以便 python setup.py install 能够正确构建它?
So I've got a directory that looks something like this:
home\
setup.py
some_python_file.py
ext\
__init__.py
c_file1.c
c_file2.c
ext_header.h
Obviously the header file is necessary to compile the c files, but the problem is that I can't get the setup script to include the header file.
My extension object is something like this:
Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c'])
Which works, but doesn't include the header file. If I change it to:
Extension('ext.the_extension', ['ext/c_file1.c', 'ext/c_file2.c', 'ext_header.h'])
It includes the '.h' file but then doesn't build when I run install. Instead it gives and error error: unknown file type '.h' (from 'ext/ext_header.h')
If I include the header file as a data file like this:
data_files=[('ext', ['ext/ext_header.h'])]
it doesn't work at all, the .h file doesn't even make it into the MANIFEST file.
So my queustion is, how do you include this extension with the header file so that python setup.py install
will build it correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一种感觉 pyfunc 正在寻求一个更标准的解决方案,但我自己确实找到了另一个解决方案。我不知道这是一个好的解决方案还是只是一个黑客,但我所做的只是将头文件添加到 MANIFEST.in 中。该文档并没有真正让人觉得这就是 MANIFEST.in 文件的用途,但它确实有效。我的 MANIFEST.in 文件现在如下所示:
其中包含该文件,并在我运行 python setup.py install 时成功编译
I have a feeling pyfunc is on track for a more standard solution, but I did find another solution on my own. I have no idea if this is a good solution or just a hack, but all I did is add the header file to the MANIFEST.in. The documentation doesn't really make it seem like this is what the MANIFEST.in file is for, but it does work. My MANIFEST.in file now looks like this:
Which includes the file and sucessfully compiles when I run
python setup.py install
从文档中,
您应该通过“include_dirs”提供包含文件。
为什么这对你不起作用?
From the docs,
You should provide the include files via "include_dirs".
Why does this not work for you?