title: How to detect whether zlib is available and whether ZIP_DEFLATED is available?
body: <p>The <a href="https://docs.python.org/3.8/library/zipfile.html#zipfile-objects" rel="noreferrer"><code>zipfile.ZipFile</code> documentation</a> says that <code>ZIP_DEFLATED</code> can be used as compression method only if <a href="https://docs.python.org/3.8/library/zlib.html#module-zlib" rel="noreferrer"><code>zlib</code></a> is available, but neither <code>zipfile</code> module specification nor <code>zlib</code> module specification says anything about when <code>zlib</code> might not be available, or how to check for its availability.</p>
  <p>I work on Windows and when I install any version of Python, <code>zlib</code> module is available. Is this different in Linux? Does <code>zlib</code> need to be installed separately?</p>
  <p>Also, what is the proper way to check for <code>zlib</code> availability? Is <code>import zlib</code> going to raise an <code>ImportError</code> if it is not available?</p>
  <p>In oher words, is this the correct way to use <code>zipfile</code>?</p>
  <pre><code>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:
      ...
  </code></pre>