Python 扩展未安装到子包中
我正在尝试构建一个 Python 扩展并使用 distutils 将其打包,但无论我如何命名它,该扩展都会安装在根包中。我的目录布局如下所示:
foo/bar/extension.c
我的 setup.py
如下所示:
from distutils.core import setup
from distutils.extension import Extension
setup(name='foo.bar.extension',
cmdclass={'build_ext': build_ext},
ext_modules=[Extension('foo.bar.extension',
sources=['foo/bar/extension.c'])]
)
我设置了一个 virtualenv
并
python setup.py install
在我的 Python shell 中运行 然后:
>>> import foo.bar.extension
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named invest_cython_core
>>> import extension #This works!
我可以更改什么以便第一个import 语句有效,而第二个语句失败?
I'm trying to build a Python extension and package it up using distutils but the extension installs in the root package no matter how I name it. My directory layout looks like this:
foo/bar/extension.c
My setup.py
looks like this:
from distutils.core import setup
from distutils.extension import Extension
setup(name='foo.bar.extension',
cmdclass={'build_ext': build_ext},
ext_modules=[Extension('foo.bar.extension',
sources=['foo/bar/extension.c'])]
)
I set up a virtualenv
and run
python setup.py install
Then in my Python shell:
>>> import foo.bar.extension
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named invest_cython_core
>>> import extension #This works!
What can I change so that the first import statement to works and the second one to fails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你需要有
foo/__init__.py
和foo/bar/__init__.py
以便 distutils 首先安装这些包,然后安装扩展模块。 (这里的错误比无声的不当行为要好,我将打开一个错误报告,以便 distutils2 表现得更好。)您是否使用自定义的 build_ext 类? (在您的示例中询问是因为
cmdclass={'build_ext': build_ext}
)这可能会导致问题。I think you need to have
foo/__init__.py
andfoo/bar/__init__.py
so that distutils installs first these packages and then the extension module. (An error would be better than a silent misbehavior here, I shall open a bug report so that distutils2 behaves better.)Are you using a custom build_ext class? (asking because of
cmdclass={'build_ext': build_ext}
in your example) That may play a part in the issue.