When I use pip freeze on the brew installed version of python 2.7 I get an import error no module named zlib.
➜ ~ pip freeze
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==7.1.2', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/site-packages/pip/__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python2.7/site-packages/pip/vcs/mercurial.py", line 10, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 38, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 5, in <module>
import zlib
ImportError: No module named lib
I think this is normally installed with python but I've installed python (2.7) with brew and an uninstall and reinstall with brew doesn't fix the issue?
➜ ~ which pip
/usr/local/bin/pip
➜ ~ which python
/usr/local/bin/python
For macOs 10.14 mojave users with Xcode-beta installed the following should work as
xcode-select --install
doesn't seem to supply the missing header files, at least not in a location that works for installing python via brew...What worked for me is as follows:
In my case I also had to reinstall some of my python modules previously installed via pip.
This is an issue with xcode not installing zlib properly.
Install the xcode CLI with:
Then before reinstalling Python with brew I check if the zlib header is where brew is looking for it via the terminal :
Then reinstall python via brew:
For those people who could not get it to work with the solutions above, use the suggestion from homebrew.
The following did nothing for me:
or
Instead it gave me an error message: