← All notes

Python zipimport: load modules from a ZIP archive on sys.path

Answer: zipimport can load Python modules and packages out of a ZIP archive on sys.path.

How imports find a ZIP file

It is usually not needed to use the zipimport module explicitly.

The built-in import mechanism applies it automatically when a sys.path item is a path to a ZIP file.

The ZIP archive can contain a subdirectory structure to support package imports.

Typically, sys.path is a list of directory names as strings.

This module also allows a sys.path item to name a ZIP file archive.

You can specify a path within the archive, such as example.zip/lib/, to import only from that subtree.

Importers are invoked only for .py and .pyc files. ZIP import of dynamic modules (.pyd, .so) is disallowed.

For an archive that only contains .py files, Python will not attempt to add the corresponding .pyc file into the archive, so importing may be slow.

The zipimporter API

ZipImportError is raised by zipimporter objects. It is a subclass of ImportError, so it can be caught as ImportError, too.

archivepath must be a path to a ZIP file, or a specific path within a ZIP file such as foo/bar.zip/lib.

ZipImportError is raised if archivepath doesn't point to a valid ZIP archive.

zipimporter is the class for importing ZIP files.

Changed in version 3.15: Zstandard (zstd) compressed zip file entries are supported.

Use find_spec() instead of find_loader() and find_module(), which were deprecated in 3.10 and later removed.

Changed in version 3.8: Previously, ZIP archives with an archive comment were not supported.

Changed in version 3.13: ZIP64 is supported.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, zipimport — Import modules from Zip archives; CPython, zipimport documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, zipimport — Import modules from Zip archives; CPython, zipimport documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:vfh5d0gx

iinventedlight. 2026. "Python zipimport: load modules from a ZIP archive on sys.path." iinventedlight Library, iil:note:vfh5d0gx, version of 2026-11-26. https://iinventedlight.com/library/notes/python-zipimport/. License: CC-BY-4.0.

@misc{iil_note_vfh5d0gx,
  author = {{iinventedlight}},
  title = {{Python zipimport: load modules from a ZIP archive on sys.path}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/python-zipimport/},
  note = {Permanent ID iil:note:vfh5d0gx. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-zipimport.md.