I have a Python 3 project with the following structure:
project/
|
+--root/
|
+--__init__.py
|
+--sub/
|
+--__init__.py
|
+--actualcode.py
I want to use "namespace packages" so that my lib shares a common namespace with other related libs in separate projects. The import statement should look like this:
from root.sub.actualcode import something
The __init__.py
file in the root folder contains the following statement to create a namespace package:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
But I cannot reference the code when I import root.sub
. It works only when I write:
from sub.actualcode import something # doesn't work with "root.sub..."!
What should I do to use root
as a namespace?