ImportError: No module named zlib on macOS Catalina

November 23, 2019

A few times now, I've had to get around an issue that happens on macOS Catalina where you try to run a Python script and it fails with an import error:

ImportError: No module named zlib

The stacktrace will differ based on what was trying to import zlib, but the fix for me (on the most recent Catalina builds) was to reinstall python2 or python3 via brew. As some others have noted, it's important to xcode-select --install first, if you haven't.

If the script is Python 2:

brew reinstall python2

If the script is Python 3:

brew reinstall python3
Picture of me with a corgi

Noah Gilmore

Hello! I'm Noah, a software developer based in the San Francisco bay area. I focus mainly on iOS, Apple platform development, and full stack web development.

  • 💻 I'm writing a macOS editor for Atlassian Confluence called Fluency
  • 📱 I wrote an app which lets you create transparent app icons called Transparent App Icons
  • 🧩 I made a puzzle game for iPhone and iPad called Trestle
  • 🎨 I wrote a CoreImage filter utility app for iOS developers called CIFilter.io
  • 👋 Please feel free to reach out on Twitter