Yai*_*aon 6 c python import directory-structure python-2.7
用 python 编写的项目,带有一些 C 扩展(不使用 SWIG 等)。我正在尝试弄清楚如何构建我的项目,以便:
当前的结构如下所示:
Project\
docs\ # mainly documentation, right?
bin\ # empty
setup.py # setup for the project, as suggested in the above link
project\
__init__.py
module.py
tests\
bla_test.py
C\ # the package of C files
file.c
file.so
other_c_stuff.c
header.h
setup.py # setup to compile the C files and create .so files
build\ # contaisn a bunch of (hopefully) irrelevant stuf
Run Code Online (Sandbox Code Playgroud)
它可以在 PyDev 中运行,但不能在 shell 中运行。理想的答案将解决以下问题:
tests)。setup.py(我应该将它们发布在这里吗?)我尝试了相对导入- 由于某种原因它们对我不起作用。我看到了这个问题的已接受答案。他说——做任何事。但我无法让进口工作。我读了这个答案,但不知道他拥有的所有东西是什么(而我没有)。接受的答案对我没有帮助,因为导入再次失败。这篇博文提供了很好的建议,但是,再次强调,进口!
我不想详细说明一般答案,因为您已经链接到了好的答案。
一些应该适合您的结构可能如下所示:
Project\
build\ # directory used by setup.py
docs\ # mainly documentation, right?
setup.py # setup for the project, as suggested in the above link
project\
__init__.py
module.py
c_package\
__init__.py
file.c
file.so
other_c_stuff.c
header.h
tests\
__init__.py
test_bla.py
Run Code Online (Sandbox Code Playgroud)
因此,project如果您就地构建 C 扩展,则可以在包及其子包中使用相对导入
python setup.py build_ext --inplace
Run Code Online (Sandbox Code Playgroud)
或创建一个setup.cfg包含
[build_ext]
inplace=True
Run Code Online (Sandbox Code Playgroud)
但仅将其用于开发,不要发布它,因为安装会失败。
setup.py构建自动化是可能的,但每当 C 源代码发生更改时,除了直接调用之外,我不知道还有什么其他方法。
| 归档时间: |
|
| 查看次数: |
1507 次 |
| 最近记录: |