Python:pip在根目录中安装子包
我有这样的结构:
setup.py
package
__init__.py
sub_package
___init__.py
sub_package2
__init__.py
如果我通过 setup.py install 安装包,那么它会按预期工作(通过将整个包复制到 site-packages 目录):
site_packages
package
sub_package
sub_package2
但是如果我运行 pip install package,则 pip 将每个子包安装为独立包:
site-packages
package
sub_package
sub_package2
我怎样才能避免这种情况呢?我使用 setuptools 中的 find_packages() 来指定包。
I have such structure:
setup.py
package
__init__.py
sub_package
___init__.py
sub_package2
__init__.py
If I install package via setup.py install, then it works as appreciated (by copying whole package to site-packages dir):
site_packages
package
sub_package
sub_package2
But if I run pip install package, then pip installs each sub-package as independent package:
site-packages
package
sub_package
sub_package2
How can I avoid this? I use find_packages() from setuptools to specify packages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:这个答案不再有效,它只是由于历史原因而保留,现在正确的答案是使用 setuptools,更多信息 https://mail.python.org/pipermail/distutils-sig/2013-March/020126.html
第一个我建议删除 setuptools :
并使用 distutils (这是 分发 Python 包的标准机制) 或 分发 你还有 distutils2 但我认为还没有准备好,对于新标准这里是如何编写 setup.py 的指南。
对于您的问题, distutils 中不存在
find_packages()
,您必须像这样添加包:如果您有很多包和子包您必须在此处编写一些代码来创建包列表是来自 Django 源代码的示例。
我认为使用 distutils 可以帮助您解决问题,我希望这可以帮助:)
NOTE: This answer is not valid anymore, it's only kept for historical reasons, the right answer right now is to use setuptools, more info https://mail.python.org/pipermail/distutils-sig/2013-March/020126.html
First of all i will recommend to drop setuptools :
And use either distutils (which is the standard mechanism to distribute Python packages) or distribute you have also distutils2 but i think is not ready yet, and for the new standard here is a guide line to how to write a setup.py.
For your problem the
find_packages()
don't exist in the distutils and you will have to add your package like this:And if you have a lot of package and sub packages you will have to make some code that create the list of packages here is an example from Django source.
I think using distutils can help you with your problem,and i hope this can help :)