[英]Python: pip installs sub-packages in root dir
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): 如果我是通过setup.py install安装软件包的,那么它可以正常工作(将整个软件包复制到site-packages目录中):
site_packages
package
sub_package
sub_package2
But if I run pip install package, then pip installs each sub-package as independent package: 但是,如果我运行pip install package,则pip将每个子软件包安装为独立软件包:
site-packages
package
sub_package
sub_package2
How can I avoid this? 如何避免这种情况? I use find_packages() from setuptools to specify packages. 我使用setuptools中的find_packages()来指定软件包。
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 注意:此答案不再有效,仅出于历史原因保留,现在正确的答案是使用setuptools,更多信息https://mail.python.org/pipermail/distutils-sig/2013-March/020126。 html
First of all i will recommend to drop setuptools : 首先,我建议您删除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. 并使用distutils (这是分发Python软件包的标准机制 )或分发您也有distutils2,但我认为还没有准备好,对于新标准, 这是如何编写setup.py的指南。
For your problem the find_packages()
don't exist in the distutils and you will have to add your package like this: 对于您的问题, distutils中不存在find_packages()
,您必须像这样添加软件包:
setup(name='package',
version='0.0dev1',
description='blalal',
author='me',
packages=['package', 'package.sub_package', 'package.sub_package2'])
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. 而且,如果您有很多软件包和子软件包,则必须编写一些代码以创建软件包列表, 这是Django来源的示例。
I think using distutils can help you with your problem ,and i hope this can help :) 我认为使用distutils可以解决您的问题 ,希望对您有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.