31

Is there any way that I can install "pip" for "Python2.7" ? I could install python2.7 by

sudo apt install python2-minimal

I tried installing pip for this.

sudo apt install python-pip / python2-pip / python2.7-pip

but none worked. Can anybody have solution for this.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Bhimasen
  • 677
  • 3
  • 8
  • 19

2 Answers2

51

Try this one:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py # Fetch get-pip.py for python 2.7 
python2 get-pip.py
pip --version
SuperStormer
  • 4,997
  • 5
  • 25
  • 35
  • 2
    Why is it necessary to use `curl` with `sudo`? – Flux Mar 13 '21 at 23:20
  • 3
    What's the purpose of `sudo add-apt-repository universe` *after* installing `curl`? – Flux Mar 16 '21 at 09:45
  • Why is it necessary to use `sudo` at all? Hint: it isn't. The script will successfully bootstrap `pip` for the current user without a problem. I am using it for Mercurial extensions which can be installed via `pip`, since on 20.04 Mercurial is still based on Python 2.7. – 0xC0000022L May 11 '21 at 07:43
  • I get this every time: /tmp/tmpoO3a0w/pip.zip/pip/_vendor/urllib3/util/ssl_.py:164: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none) ERROR: No matching distribution found for pip<21.0 – Jonathan Rys Jul 14 '21 at 16:11
  • The following worked for me. `curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py` `sudo python2 get-pip.py` `pip --version` P.S I am not good with markdown :P – Waqar Rashid Jul 21 '21 at 12:26
  • I removed sudo from curl and the python get-pip.py execution. Examples on https://github.com/pypa/get-pip don't include sudo for executing the python script. given the nature of this script, sudo'ing could be dangerous. – OldBuildingAndLoan Aug 22 '21 at 00:46
  • 1
    You don't need to add universe – ndtreviv Dec 03 '21 at 10:49
  • `pip --version` refers to python3. You should use `pip2 --version` instead. – SuB Oct 03 '22 at 15:19
22

Pip for Python 2 is not included in the Ubuntu 20.04 repositories.

Try this guide which suggests to fetch a Python 2.7 compatible get_pip.py and use that to bootstrap pip.

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
pol92
  • 427
  • 3
  • 7
  • This is weird because after the instruction to download it (curl) I execute it as described but it results in an error message: `File "/tmp/tmp62UdRM/pip.zip/pip/_internal/cli/main.py", line 60` and `sys.stderr.write(f"ERROR: {exc}")`. So this is Python3 code, not Python2. Further investigation showed that these f-strings are all over the place in many files in the ZIP. The mentioned `get-pip.py` script might have dropped Python2 support completely :-( – Alfe Jan 31 '21 at 02:54
  • 5
    This guide did not work for me in Python 2.7. Had to use this URL to download get-pip.py https://bootstrap.pypa.io/2.7/get-pip.py – Gabriel Cappelli Feb 02 '21 at 11:32
  • then the above guide has to be updated with the correct URL – pol92 Feb 04 '21 at 11:05
  • 1
    The URL has been updated in the guide, works fine now, good guide, +1 – Rayner Apr 20 '21 at 05:57
  • Something really basic that tripped me up: it doesn't matter much where you store get-pip.py because it's throw-away. After executing this script, I could see the commands it installed by `ls /usr/local/bin/pip*` – Bob Stein Nov 09 '22 at 20:58
  • For those who are paranoid (like me) and don't know the Python ecosystem well (like me), `pypa.io` is the domain for Python packages, so I'm assuming reasonable trust in this case. – Robert Dundon Feb 14 '23 at 21:03