How to create namespace packages in Python? -
i have python 3 project following structure:
project/ | +--root/ | +--__init__.py | +--sub/ | +--__init__.py | +--actualcode.py i want use "namespace packages" lib shares common namespace other related libs in separate projects. import statement should this:
from root.sub.actualcode import the __init__.py file in root folder contains following statement create namespace package:
from pkgutil import extend_path __path__ = extend_path(__path__, __name__) but cannot reference code when import root.sub. works when write:
from sub.actualcode import # doesn't work "root.sub..."! what should use root namespace?
namespace packages can built distribute. trick add following line parameter of setup:
setup( # ... namespace_packages = ["root"] ) the rest of example in question correct.
Comments
Post a Comment