Python – ‘NoneType’ object has no attribute ‘decompressobj’ while installing Bootstrap setuptools

python

I am trying to install python 3.2, and to get setuptools and pip in python 3.2. Everything seems to work right in python 2.7. However when I try to install setuptools using this code wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3.2 I get the following error

Extracting in /tmp/tmpcwnav_
Traceback (most recent call last):
  File "<stdin>", line 332, in <module>
  File "<stdin>", line 329, in main
  File "<stdin>", line 51, in _install
  File "/usr/local/lib/python3.2/contextlib.py", line 28, in __enter__
    return next(self.gen)
  File "<stdin>", line 101, in archive_context
  File "/usr/local/lib/python3.2/zipfile.py", line 1004, in extractall
    self.extract(zipinfo, path, pwd)
  File "/usr/local/lib/python3.2/zipfile.py", line 992, in extract
    return self._extract_member(member, path, pwd)
  File "/usr/local/lib/python3.2/zipfile.py", line 1035, in _extract_member
    source = self.open(member, pwd=pwd)
  File "/usr/local/lib/python3.2/zipfile.py", line 978, in open
    close_fileobj=not self._filePassed)
  File "/usr/local/lib/python3.2/zipfile.py", line 487, in __init__
    self._decompressor = zlib.decompressobj(-15)
AttributeError: 'NoneType' object has no attribute 'decompressobj'

Based on some googling, it looks like I am getting the problem because zlib has not been installed. I do not have this problem when trying to install setuptools for python 2.7. I went into python 3.2 and tried to import zlib and got an error message when I tried that. I also tried to do sudo apt-get install zlib and got the error message E: Unable to locate package zlib. I did not get error messages when I tried sudo apt-get install zlib1g or sudo apt-get install zlib1g-dev` I really have no idea what's going on. How do I get zlib for python 3.2 (or otherwise fix this problem?)

Best Answer

Your problem seems to be you compiled Python without support for zlib. Make sure you have zlib-devel installed (sudo apt-get install zlib1g-dev) before compiling Python. There's nothing wrong with using Python compiled by you in addition or instead of the system one. However you have to remember to be explicit when invoking Python and invoke the one you intend to use by specifying full path like /usr/local/bin/python instead of plain python. Alternatively you can add (/usr/local/bin/) to your PATH before /usr/bin/ so that when you type python system runs your compiled Python.

Related Question