python – 使用setuptools,命名空间包__init__.py文件何时消失?

setuptools documentation非常明确地将命令添加到命名空间中的__init__.py文件中:

You must NOT include any other code and data in a namespace package’s __init__.py. Even though it may appear to work during development, or when projects are installed as .egg files, it will not work when the projects are installed using “system” packaging tools — in such cases the __init__.py files will not be installed, let alone executed.

然而,我不明白这些“系统”包装工具是什么.这些是什么?我怎样才能重现__init__.py文件消失的情况?

最佳答案 @ Anzel的评论看起来很好,我会说
PEP-420证实了这一点.在其
Rationale section,我们读到:

Namespace packages are designed to support being split across multiple directories (and hence found via multiple sys.path entries). In this configuration, it doesn’t matter if multiple portions all provide an __init__.py file, so long as each portion correctly initializes the namespace package. However, Linux distribution vendors (amongst others) prefer to combine the separate portions and install them all into the same file system directory. This creates a potential for conflict, as the portions are now attempting to provide the same file on the target system – something that is not allowed by many package managers. Allowing implicit namespace packages means that the requirement to provide an __init__.py file can be dropped completely, and affected portions can be installed into a common directory or split across multiple directories as distributions see fit.

所以是的,我们不能再向__init__.py文件中添加任何代码,因为操作系统包管理器(和其他人)更愿意将它们合并到一个目录树中.

点赞