right way to use zipimport, zipimport.ZipImportError: not a Zip file

dieter dieter at handshake.de
Tue Aug 14 01:10:52 EDT 2018


iMath <redstone-cold at 163.com> writes:
> ...
> It seems possible in Python to use `zipimport` to directly use the zip archive of the module without extraction, I wonder what is the right way to use `zipimport`.

Your problem may come from the following restriction
(cited from the Python 2 documentation of `zipimport`):

  ZIP archives with an archive comment are currently not supported.

This implies that "zipimport" cannot handle all (valid) zip archives.


Another citation from the documentation mentioned above:

   This module adds the ability to import Python modules (*.py,
   *.py[co]) and packages from ZIP-format archives. It is usually not
   needed to use the zipimport module explicitly; it is automatically
   used by the built-in import mechanism for sys.path items that are
   paths to ZIP archives.

This means, you usually do not use "zipimport" yourself. Instead,
you ensure that `sys.path` contains a path leading to a zip archive
or a directory inside a zip archive.
I have used this feature in the past - and it works for
supported zip archives.




More information about the Python-list mailing list