Forums

Getting error with zlib

Pls Help,

I'm getting error zipimport.ZipImportError: can't decompress data; zlib not available when i run pip install. I'm using virtualenv for my application, but suddenly the xhtmltopdf is not working so i try to re-install again using pip install but i got that error.

Thanks in advance

Hi Cmora. Could you please be more specific about what you're actually trying to do. From what I understand so far, you've got a virtualenv for an application of yours and you're trying to install an xhtmltopdf package. However, when you do the pip install operation, you're getting an error that the zipimport module can't find zlib - have I understood you correctly?

It sounds like a strange problem because zlib should definitely be available on the system, even in a virtualenv. Without more details, I can only suggest creating a new virtualenv from scratch and seeing if you still have the same problem (I suggest leaving your original virtualenv intact, just trying a new one as an experiment).

Q - However, when you do the pip install operation, you're getting an error that the zipimport module can't find zlib - have I understood you correctly? A - Yes your correct.

Yes i also don't understand why is that. But thanks i try to create the virtualenv again.

Thats work i created another virtualenv got no error encounter. Thanks Cartroo

You're welcome. It sounds to me as if something that got installed in the other virtualenv broke the environment in some way that some of the system libraries couldn't be found.

Looking at the source code, it appears that error is generated here when this function returns NULL. The reasons for this appear to be if the zip file you're importing contains a module called zlib (which looks like it breaks the whole zipimport infrastructure) or if the zlib module can't be found. As far as I'm aware that module is compiled directly into the Python binary itself, however (I may be wrong!), so I'm quite puzzled why it can't be found. Also, if the zlib module doesn't contain a decompress() function that would also cause a problem, but that shouldn't happen either.

So, it's very puzzling. If you still have the old virtualenv around, you might like to check if you had a file zlib.py or zlib.pyc (or zlib.pyo) around in it somewhere - it appears that will mess things up quite badly.

EDIT

As it happens I can't reproduce this even putting a zlib.py and zlib.pyc file into a zip archive with another library - I can still import the other library fine. Very odd. Well, the important thing is that it's working for you now, but it would be very interesting to know what caused the problem for future reference.