Package-1/namespace/__init__.py
Package-1/namespace/module1/__init__.py
Package-2/namespace/__init__.py
Package-2/namespace/module2/__init__.py
with
- Package-1
- Package-2 in PYTHONPATH
If you want to import
import namespace.module1
import namespace.module2
module2 won't be found
- Python look for namespace.module2.
- It parses PYTHONPATH in the declared order
- Package-1 found
- Parsing stopped
- moule2 not present inside --> ImportError
In __init__.py
, write:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
sources:
- http://stackoverflow.com/questions/8936884/python-import-path-packages-with-the-same-name-in-different-folders
- http://stackoverflow.com/questions/6630394/import-python-modules-with-the-same-name
- http://stackoverflow.com/questions/1675734/how-do-i-create-a-namespace-package-in-python
- https://www.python.org/dev/peps/pep-0420