The zipfile.ZipFile documentation says that ZIP_DEFLATED can be used as compression method only if zlib is available, but neither zipfile module specification nor zlib module specification says anything about when zlib might not be available, or how to check for its availability.
I work on Windows and when I install any version of Python, zlib module is available. Is this different in Linux? Does zlib need to be installed separately?
Also, what is the proper way to check for zlib availability? Is import zlib going to raise an ImportError if it is not available?
In oher words, is this the correct way to use zipfile?
try:
    import zlib
except ImportError:
    zlib = None
compression = zipfile.ZIP_STORED if zlib is None else zipfile.ZIP_DEFLATED
with zipfile.ZipFile(file, mode, compression) as zf:
    ...