Python pip
Python pip

So the other day I was upgrading some old test instances and setting up some roles using Ansible and the role geerlingguy.pip, and ran into an issue. The issue was that pip wouldn’t work, throwing the below error message:

# pip3 install docker
 Traceback (most recent call last):
   File "/usr/local/bin/pip3", line 7, in 
     from pip._internal.cli.main import main
   File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
     sys.stderr.write(f"ERROR: {exc}")

The reason for this is that the installed version of pip, version 21, is incompatible with Python versions lower than 3.6. Luckily, fixing this was easy. All the instances I had deployed getting this update were all running Python 3.5, so I used the below to correct the problem.

update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1
curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
python get-pip.py
python -m pip install --upgrade "pip < 21.0"

This ensures that Python is linked to the python3 executable, downloading a bootstrapper script for Python 3.5, executes the bootstrapper that removes pip version 21 and then installs pip again with the latest version below version 21.

You should now be able to use pip as usual.

By Jostein Elvaker Haande

"A free society is a society where it is safe to be unpopular" - Adlai Stevenson

Leave a Reply

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