Issue 20899: Nested namespace imports do not work inside zip archives (original) (raw)

Importing modules from subdirectories as "implicit namespace packages" (PEP 420) inside a ZIP archive only works one level deep. Imports from within nested namespaces fail with "ImportError: No module named 'XXX'".

I am attaching an archive with example directory/file structure. To reproduce the problem, run the following from where you unzipped it:

python

import sys sys.path += ['project1', 'project2.zip', 'project3', 'project4.zip'] import parent.child.hello1 Hello 1 import parent.child.hello2 ImportError: No module named 'parent.child.hello2' import parent.child.hello3 Hello 3 import parent.child.hello4 ImportError: No module named 'parent.child.hello4' import boo boo! import parent.boo boo!

Tested on WinXP SP3 with Python 3.3.5 and 3.4.0rc3.

It appears this issue has been fixed, as I am unable to reproduce it on Windows 10/Python 3.7:

Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import sys sys.path += ['project1', 'project2.zip', 'project3', 'project4.zip'] import parent.child.hello1 Hello 1 import parent.child.hello2 Hello 2 import parent.child.hello3 Hello 3 import parent.child.hello4 Hello 4 import boo boo! import parent.boo boo!