I have a Python 3.6 virtual environment in which (among others) two libraries are installed that share a common top directory shared_name
. It does not contain a __init__.py
. As far as I understand it, that should be an implicit namespace package (PEP 420)
When I add to the PYTHONPATH
a source module that also uses that name at the top level, then I cannot get the latter directory to be found. Python does not find it when both shared_name
directories have an __init__.py
, nor when none have it.
Adding pkgutils.extend()
to one or both __init__.py
files does not help either.
The structure is like this:
lib/python3.6/site-packages/shared_name/p1
lib/python3.6/site-packages/shared_name/p2
source_package/shared_name/infrastructure.py
Immediately under shared_name
there is no __init__.py
file. At run time, sys.path
includes source_package
, but shared_name.__path__
only contains lib/python3.6/site-packages/shared_name
, not source_package
.
I'm at a loss how I can debug it or what might be wrong with it.
Is mixing installed and source packages not allowed for namespace packages? (The documentation seemed silent on this topic to me.)
Using PYTHONVERBOSE
did not help me either. I don't understand for instance why
# destroy shared_name
occurs before any evidence that it was tried - let alone matched - at all.