10

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.

shuttle87
  • 15,466
  • 11
  • 77
  • 106
user1010997
  • 523
  • 5
  • 13
  • Please add MVE. It may help in debug. – Grzegorz Bokota Aug 03 '19 at 19:12
  • I agree about the MVE. The exact imports you're using might play a role. Have you tried putting `infrastructure.py` into `shared_name/p3/`? – Roland Weber Aug 07 '19 at 06:08
  • What does "MVE" mean? – user1010997 Aug 16 '19 at 11:42
  • 1
    I believe you can get the answers you need from the duplicate I marked. If not, you need to clarify your question with a [**M**inimal **V**erifiable **E**xample](https://stackoverflow.com/help/minimal-reproducible-example). It's unclear exactly how you are importing each and what the directory structures are, and what the expected behavior is. – MyNameIsCaleb Sep 22 '19 at 18:26

0 Answers0