Skip to content Skip to sidebar Skip to footer

Why Do I Need To Include Sub-packages In Setup.py

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

Solution 1:

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(),
    ...
)

Post a Comment for "Why Do I Need To Include Sub-packages In Setup.py"