How-To: Use Zlib and Ez_Setup.py in Python 2.5

As many have noticed while install easy_install on Python 2.5, a mysterious message appears that a previously very prevalent package has disappeared from python.

[root@server]# python

Python 2.5.4 (r254:67916, Jul 11 2009, 12:13:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import zlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named zlib
>>>

This is made even more serious when you try to install ez_setup.py

[root@server ~]# cd ezsetup
[root@server ezsetup]# wget http://peak.telecommunity.com/dist/ez_setup.py
--12:24:21--  http://peak.telecommunity.com/dist/ez_setup.py
Resolving peak.telecommunity.com... 209.190.5.234
Connecting to peak.telecommunity.com|209.190.5.234|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9716 (9.5K) [text/plain]
Saving to: `ez_setup.py'

100%[=======================================>] 9,716

12:24:21 (129 KB/s) - `ez_setup.py' saved [9716/9716]

[root@server ezsetup]# python ez_setup.py
Downloading http://pypi.python.org/packages/2...
Traceback (most recent call last):
  File "ez_setup.py", line 270, in <module>
    main(sys.argv[1:])
  File "ez_setup.py", line 204, in main
    from setuptools.command.easy_install import main
zipimport.ZipImportError: can't decompress data; zlib not available

Well, here’s how you would go about fixing it.

  1. Make sure that Python 2.4 is installed on your machine, make sure to edit the path environment so python defaults back to 2.5
  2. Get the directory of python2.4 with whereis python2.4, for example, /usr/lib/python2.4, and cd into the directory
  3. cd lib-dynload
  4. whereis python2.5 ie /usr/local/lib/python2.5
  5. cp zlibmodule.so /dirToPython2.5/lib-dynload/ (IE: /usr/local/lib/python2.5/lib-dynload/)
  6. python
  7. import zlib

And now you should see a warning (but not an error) telling you that there’s a version mismatch between the libraries. This is because zlibmodule was compiled for 2.4, but is still usable in 2.5

>>> import zlib
__main__:1: RuntimeWarning: ...
>>>

After that, go back to ez_setup.py and try it again

[root@server lib-dynload]# cd /root/ezsetup
[root@server ezsetup]# ls
ez_setup.py
[root@server ezsetup]# python ez_setup.py
Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg
ez_setup.py:204: RuntimeWarning: ...
  from setuptools.command.easy_install import main
Processing setuptools-0.6c9-py2.5.egg
Copying setuptools-0.6c9-py2.5.egg to /usr/local/lib/python2.5/site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.5 script to /usr/local/bin

Installed /usr/local/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9
[root@server ezsetup]#

And there you have it, using zlib on python 2.5

This entry was posted in Programming, Python, Snippets. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>