Python: No Module named Zlib, Mac OS X El Capitan 10.11.6

Luis Valdez picture Luis Valdez · Aug 3, 2016 · Viewed 8.5k times · Source

I'm trying to convert my python command line application to an app with py2app. Everytime I try to import zlib or try to install setuptools , I get an error : no module named zlib.

Python was installed with brew. I searched every corner of the internet and stack overflow, I have reinstalled python with brew , I have installed all Xcode CLI related stuff with :

xcode-select --install

I also ran :

ls /usr/include/zlib.h

and I can see that zlib is there where it is supposed to be.

Reinstalled with:

brew reinstall python

Unfortunately that didn't work for me. I can't get what is wrong.

Any ideas?

Answer

Frans picture Frans · Nov 20, 2018

I had the same issue and the solution at https://github.com/Homebrew/homebrew-core/issues/29176 worked for me: re-install python@2:

brew reinstall python@2

(Before I tried this I also tried installing zlib with Homebrew -- brew install zlib; this may or may not have contributed to it working.)