文件:
project/
setup.py
proj_ex/
__init__.py
corecode.py
>>pip install xxx
安装包过程:
先找到setup.py
from setuptools import setup
setup(
...
name_space_packages = ['proj_ex']
...
)
name_space_packages 指向核心代码包:proj_ex
# __init__.py
__import__("pkg_resources").declare_namespace(__name__)
(1) pkg_resources是一个安装包的工具
(2) _import_()加载导入,import的隐式版
(3) 此处的_name_指的是proj_ex
(4) corecode.py加载到proj_ex的命名空间之中
参考:
[1] https://stackoverflow.com/questions/7785944/what-does-import-pkg-resources-declare-namespace-name-do/37104834
[2] https://stackoverflow.com/questions/5064951/packaging-common-python-namespaces