如何在setup.py脚本中为Python扩展模块指定头文件?使用源文件列出如下不起作用.但我无法弄清楚在哪里列出它们.
from distutils.core import setup, Extension
from glob import glob
setup(
name = "Foo",
version = "0.1.0",
ext_modules = [Extension('Foo', glob('Foo/*.cpp') + glob('Foo/*.h'))]
)
Run Code Online (Sandbox Code Playgroud)
iEl*_*ric 16
在setup.py之外添加MANIFEST.in文件,其中包含以下内容:
graft relative/path/to/directory/of/your/headers/
Run Code Online (Sandbox Code Playgroud)
小智 7
尝试将标题 kwarg 设置为 setup()。我不知道它在任何地方都有记录,但它有效。
setup(name='mypkg', ..., headers=['src/includes/header.h'])
Run Code Online (Sandbox Code Playgroud)
我在setuptools上遇到了很多麻烦,它甚至都不再有趣了.以下是我最终必须使用解决方法来生成带有头文件的工作源代码分发:我使用了package_data.
我正在分享这个,以便潜在地拯救别人的恶化.如果您知道更好的工作解决方案,请告诉我.
详情请见:http: //bitbucket.org/blais/beancount/src/ccb3721a7811a042661814a6778cca1c42433d64/setup.py?fileviewer=file-view-default#setup.py-36
# A note about setuptools: It's profoundly BROKEN.
#
# - The header files are needed in order to distribution a working
# source distribution.
# - Listing the header files under the extension "sources" fails to
# build; distutils cannot make out the file type.
# - Listing them as "headers" makes them ignored; extra options to
# Extension() appear to be ignored silently.
# - Listing them under setup()'s "headers" makes it recognize them, but
# they do not get included.
# - Listing them with "include_dirs" of the Extension fails as well.
#
# The only way I managed to get this working is by working around and
# including them as "packaged data" (see {63fc8d84d30a} below). That
# includes the header files in the sdist, and a source distribution can
# be installed using pip3 (and be built locally). However, the header
# files end up being installed next to the pure Python files in the
# output. This is the sorry situation we're living in, but it works.
Run Code Online (Sandbox Code Playgroud)
在我的OSS项目中有相应的票证:https: //bitbucket.org/blais/beancount/issues/72