I'm using Python 3.8.2, and I've created a namespaced package, called fruit
. The structure of this namespaced package is as follows:
fruit
└── banana
└── __init__.py
The __init__.py
file here only contains fruit="banana"
.
Note, I'm creating this package using implicit namespace packages (as per Python 3.3), and referring to the packages using packages=find_namespace_packages(include=['fruit.banana', 'fruit.banana.*'])
in setup.py
.
The issue I'm facing, occurs when using the dependency in a project that uses the same package naming. An example project structure of a project using the fruit
dependency:
fruit --> top level package name
├── __init__.py
└── banana
├── __init__.py
└── run.py
Both __init__.py
files are empty, the contents of the run.py
file are this:
from fruit.banana import fruit
if __name__ == '__main__':
print(fruit)
When running this run.py
, I'm getting a ImportError: cannot import name 'fruit' from 'fruit.banana' (/path/to/project/.../fruit/banana/__init__.py)
. However, when I change the package name marked with top level package name in the directory structure above to anything else than fruit
, it runs fine.
How can I reuse the same package names when creating a namespaced package?