all Python 3Modules & importsterm
zipimport
module
Imports Python modules directly from a ZIP archive placed on sys.path.
Syntax
import zipimport
You rarely call this module directly: putting a .zip path on sys.path is enough for import to find modules inside — that is how zipapp application archives work. Only .py and .pyc files are importable; C extensions (.so, .pyd) cannot be loaded from an archive. To build a runnable program archive use zipapp; to just read files from an archive use zipfile.
Examples
import sys, zipfile
with zipfile.ZipFile("lib.zip", "w") as zf:
zf.writestr("greet.py", "def hi():\n return 'hi from zip'\n")
sys.path.insert(0, "lib.zip")
import greet
print(greet.hi(), type(greet.__loader__).__name__) # → hi from zip zipimporter
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy