from distutils import tests
即使distutils / tests中没有__init__.py,这似乎也不会引发任何错误。
到目前为止,我的理解是__init__.py对于要导入的包或子包是必不可少的
最佳答案
这显然在Python 3.2中有所改变。在setuptools documentation
我们发现:
Anyway, find_packages() walks the target directory, filtering by inclusion patterns, and finds Python packages (any directory). On Python 3.2 and earlier, packages are only recognized if they include an __init__.py file. Finally, exclusion patterns are applied to
但是,在Python 3.6 documentation中,我们发现仍然需要init.py。
我的理解是,当前行为接受sys.path中带有.py文件的任何目录。但是,为此我很难找到一些官方的东西。
关于python - 导入包本质上是__init__.py,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43706436/