This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients jaraco
Date 2019-04-27.08:04:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
As discovered in, if a PEP 420 namespace package is represented by an implicit directory (that is, there's no explicit entry for the directory, only entries for the contents of the directory), that directory won't be picked up as a namespace package. The following code illustrates the issue:

zp $ cat                                                                                                                                                          
import zipfile

def make_pkgs():
    zf = zipfile.ZipFile('', 'w')
    zf.writestr('pkg/', b'')

    zf = zipfile.ZipFile('', 'w')
    zf.writestr('ns/pkg/', b'')

__name__ == '__main__' and make_pkgs()
zp $ python                                                                                                                                                       
zp $ env python3.7 -c "import pkg"                                                                                                                       
zp $ env python3.7 -c "import ns.pkg"                                                                                                                 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ns'

As you can see, in, the `pkg` directory is implied, but despite that condition, `pkg` is importable.

However, with, the name `ns` is not visible even though it's present in the zipfile and would be importable if that zipfile were extracted to a file system.

zp $ unzip
 extracting: ns/pkg/
zp $ python3.7 -c "import ns.pkg" && echo done

If you were to reconstruct that zip file on the file system using standard tools or explicitly include 'ns/' in the zip entries, the namespace package becomes visible:

zp $ rm                                                                                                                                                          
zp $ zip -r ns                                                                                                                                                   
  adding: ns/ (stored 0%)
  adding: ns/pkg/ (stored 0%)
  adding: ns/pkg/ (stored 0%)
  adding: ns/pkg/__pycache__/ (stored 0%)
  adding: ns/pkg/__pycache__/__init__.cpython-37.pyc (deflated 23%)
zp $ rm -r ns                                                                                                                                                                  
zp $ env python3.7 -c "import ns.pkg" && echo done                                                                                                    

For consistency, the zip import logic should probably honor implicit directories in zip files.
Date User Action Args
2019-04-27 08:04:15jaracosetrecipients: + jaraco
2019-04-27 08:04:15jaracosetmessageid: <>
2019-04-27 08:04:15jaracolinkissue36740 messages
2019-04-27 08:04:15jaracocreate