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

六月ゝ 毕业季﹏ 提交于 2019-11-29 14:45:27

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(),
    ...
)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!