I was having the same error while working on MAC
My MAC OS version
$ uname -vDarwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64
python3.4 is used here
Issue(s)
zlib not available while using python3.4
$ python3.4 get-pip.py Traceback (most recent call last): File "get-pip.py", line 20204, in main() File "get-pip.py", line 152, in main bootstrap(tmpdir=tmpdir) File "get-pip.py", line 82, in bootstrap import pip zipimport.ZipImportError: can't decompress data; zlib not available
Rebuilding Python fails
./configure --with-zlib-dir=/usr/local/lib
... configure: WARNING: unrecognized options: --with-zlib-dir ...
Solution
Ensure zlib is installed . By default it will be installed in /usr/lib
ls /usr/lib/libz.*
If not installed, a. download and install i)from zlib.net site or ii) from a git repo like the below
git clone https://github.com/madler/zlib.git
or iii). Use the zlib source in the python source directory Modules/zlib
b. Install zlib
./configure --prefix=/usr/local
make
sudo make install
2.Edit /Module/Setup by uncommenting the line below "#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz "
3.Rebuild the Python3.4 from source again
cd ${PYTHON_SRC_CODE_DIR} ./configure --prefix=${PYTHON_HOME_DIR}make
sudo make install
4.Confirm installation Please note gzip depends on zlib.
nbr_repeation=100f=open("some_file.txt","at")for line in range(nbr_repeation):
print('[{}] This file will be compressed using python zlib/gzipmodule'.format(line),file=f)f.close()f=open("some_file.txt","rt")import gzip
gz=gzip.open('some_file.gz', 'wt') for line in f : gz.write(line)gz.close() # Like to be clean exitf.close() # Like a clean exit"""confirm the creation of the compressed gzip files"""import osprint([ (file,os.stat(file)[6],"bytes") for file in os.listdir(".") if file.startswith("some")])
sudo apt-get build-dep python
or similar before running configure + make to build your own Python from source. That ensures you have all of the necessary development header files for the libraries Python likes to link to. – gps Sep 11 '12 at 17:03