Why do I need to include sub-packages in setup.py

后端 未结 1 1024
日久生厌
日久生厌 2020-12-19 00:07

I have a python package called mltester which contains two sub-packages (actions, dialogs) and a main script ml_tester.py

相关标签:
1条回答
  • 2020-12-19 01:03

    Because packages do not do any package lookup in subtree. Adding a package to packages will only include the package itself and all direct submodules, but none of the subpackages.

    For example, if you have a source tree with package spam containing a module eggs and subpackage bacon:

    src
    └── spam
        ├── __init__.py
        ├── eggs.py
        └── bacon
            └── __init__.py
    

    Specifying packages=['spam'] will include only spam and spam.eggs, but not spam.bacon, so spam.bacon will not be installed. You have to add it separately to include the complete source codebase: packages=['spam', 'spam.bacon'].

    To automate the building of the packages list, setuptools offers a handy function find_packages:

    from setuptools import find_packages, setup
    
    setup(
        packages=find_packages(),
        ...
    )
    
    0 讨论(0)
提交回复
热议问题