Configure and compile Python with Zlib

by on Jun.26, 2005, under Linux, Python, Zope

I just spent an hour trying to figure this out, AGAIN! To compile Zlib support into your Python interpreter, do this:

1. Install the Zlib-dev package for your distribution. (you probably have zlib already, but not the dev package)
On Ubuntu it’s called ‘zlib1g-dev’, on others it might just be: zlib-dev or zlib-devel. Do a search on your distro package lists to find it.
You should end up with a ‘zlib.h’ file in your system. In mine, Ubuntu, I have /usr/include/zlib.h

2. Get your python sources to compile and run the configure script like so:
./configure –with-zlib=/usr/include

See there that I included the ‘/usr/include’ directory to find zlib.h in? After the make && make install it worked great!

Keep in mind your mileage may vary, but this might help I hope. More importantly, now I can remember how I did this! :)




  • http://www.1stbyte.com Greg

    Originally posted by Nico:
    It worked !!!! if you were a girl I would kiss you

    thnx mate

    • sriram

      Thanks for the posting Nico!! Helped greatly..

  • many thanx

    just wasted half a day on this myself – another pointer for those having trouble re-installing, make sure to unset your PYHTONHOME and PYHTONPATH env vars … son of a …

  • http://www.katharineosborne.com Katharine Osborne

    Thanks! This was driving me nuts :-/

  • Leo

    Thanks!! I did a clean install of Python 2.6.5 and was getting

    ImportError: No module named zlib

    but then I followed your instructions, reinstalled python, and now it works.

  • Kernc

    nothing worked for me until I manually edited ./Python2.5/Modules/Setup and uncommented the line starting with:
    zlib zlibmodule.c …

    quite sad. :S

  • Matthew Rapaport

    I tried the above, also un-commenting the zlib line in Modules/Setup, but while the configure ran, I end up with the message  “unrecognized options: –with-zlib” So still no luck getting this to run. Strange that the Python that appears to ship with this box (2.4.2) already has zlib built in (I can “import gzip” while this later downloaded version (2.7.2) does not, or at least it doesn’t work when installed…

    This is not my forte.

    • Anonymous

      Yeah, maybe on python 2.7 its done differently. But on my reply to another comment, it occurred to me that the whole deal with 64bit systems may cause some problems. Like, if you have 32bit python, you’ll need 32bit libs intsalled for zlib too, right? Just a thought.

      Do you need your own compiled version? Or can you just install your distro’s package of it? (which *is* easier, IMHO)

  • Anonymous

    whooaaa, man!  I almost threw my computer out the window on this!!

    I’m on CentOs, so I installed zlib-dev this way:
    yum install zlib-devel.x86_64

    then, I un-commented #zlib in the Setup file of Python

    then, I did: (note that I had the same error as Matthew with the with-zlib thing, so I just ommited it, to see what would happen)
    ./configure
    make
    make install

    from within the Python folder (classic installation)

    then I tried to import zlib, and it worked!

    such a complicated process, I can’t believe this…

    Fred

    • Anonymous

      Well I am glad you got it to work! I posted this years ago. I kept having to deal with this for a few years and decided to post a “how-to” to myself. Funny thing is, I haven’t had to deal with it since! LOL! I just use the packages, and haven’t had a problem. But I suppose depends on software you are using and versions you need, plus these 64bit systems and libs complicate things a little.

  • Mult

    In point 2, do you mean to run python with
    ./configure –with-zlib=/usr/include 
    Im just trying to get this right

  • http://twitter.com/benstokes Ben Stokes

    Thanks – worked for me. Pretty annoying how this isn’t shown as an option in ./configure –help. 

3DS Bundles at GameStop.com


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

1st Byte Solutions