开发者

Python: pip installs sub-packages in root dir

开发者 https://www.devze.com 2023-01-24 08:38 出处:网络
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 packa

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_p开发者_开发技巧ackage
    sub_package2

How can I avoid this? I use find_packages() from setuptools to specify 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


First of all i will recommend to drop setuptools :

Python: pip installs sub-packages in root dir

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:

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.

I think using distutils can help you with your problem,and i hope this can help :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号