Search code examples
pythondjangopython-3.xpipzlib

Can't fix "zipimport.ZipImportError: can't decompress data; zlib not available" when I type in "python3.6 get-pip.py"


I was trying to install Django. Turns out that course's teacher said that we will be working with Python 3.6 I install Python 3.6. Now it's my default, it somewhat replaced the last version I had; which is Python 3.5. Everything ok until that. But when I want to install Django doing "pip3 install django", it tells me that the module is already satisfied and therefore installed.

I run "python3" command into my terminal. It runs Python 3.6. I try to import Django, and boom... "No module named 'django'".

Then I realized pip3 was actually installing my modules into Python 3.5 and not 3.6. So what I do is to install pip in Python 3.6.

I download get-pip.py and proceed to execute it with Python 3.6 typing in "python3.6 get-pip.py".

Here is when the damn "zipimport.ZipImportError: can't decompress data; zlib not available" goes in. I've tried a ton of things and no one of them fixed the %^$! problem. I'm really tired.

What I have already tried: python3.6 -m pip install django, which output is "/usr/local/bin/python3.6: No module named pip"

apt install zlib, which output is "E: Unable to locate package zlib"

apt install zlib1g-dev, which says that it's already installed; the problem persists though.


Solution

  • I also came across this problem (while creating a simple installer for pyenv). Here's how I solved it for Mac and Linux:

    Ubuntu 20.04, 18.04

    You need the zlib development files, and probably zlib itself too:

    sudo apt install -y zlib1g-dev zlibc
    

    If you're missing zlib, it's likely that the next problem you'll run into is with openssl, so it's probably best to get that now as well:

    sudo apt install -y libssl-dev
    sudo apt install -y libssl1.1 || sudo apt install -y libssl1.0
    

    macOS

    I believe this comes with XCode CLI Tools (or at least I didn't have to custom install it Big Sur):

    xcode-select --install