5

Launching some small VMs in GCP and thought I would give Ubuntu 20.04 LTS minimal a try. After doing an "apt update; apt upgrade" I'm able to install packages like Apache, but having zero luck with PIP:

root@ubuntu-rr58:/home/me# apt install python-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python-pip

I have verified the Universe, Multiverse and Restricted repositories are available:

root@ubuntu-rr58:~# grep ^deb /etc/apt/sources.list
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ focal main restricted
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ focal universe
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://us-central1.gce.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
John Heyer
  • 181
  • 2
  • 8

2 Answers2

9

The package is called python3-pip. Python 2.7 is not shipped anymore with Ubuntu 20.04, nearly all python related packages are now called python3-*.

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
  • 1
    **apt install python3-pip** does work, but I need the python-geoip & python-geoip-geolite2 packages which unfortunately only run on Python2. So I'll either have to go back to Ubuntu 18 or just find a Python3-based GeoIP library as a replacement – John Heyer May 08 '20 at 14:22
  • Actually, found a [hack](https://layer77.net/2020/05/08/ubuntu-20-04-unable-to-locate-package-python-pip/) to get around this - just install the packages with pip3, then use **sys.path.insert** to add them to the Python2 script. – John Heyer May 08 '20 at 15:20
  • 2
    @JohnHeyer geoip has been deprecated for quite some time; consider taking this opportunity to move to geoip2. – Michael Hampton May 08 '20 at 21:56
  • 1
    @JohnHeyer : You have posted an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). The solution to the question you **should** have asked is [here](https://stackoverflow.com/a/32587938/478891). – Eric Towers May 08 '20 at 21:57
  • 1
    geolite is free, while geoip2 requires a paid subscription. – John Heyer May 11 '20 at 08:43
4

To get the Python 2 version of pip back, you can use get-pip, which is a single script that downloads and installs the latest version of pip (for Python 2 or 3, whichever version you run the script with):

$ curl -O https://raw.githubusercontent.com/pypa/get-pip/master/get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1824k  100 1824k    0     0  2211k      0 --:--:-- --:--:-- --:--:-- 2211k

$ python get-pip.py 
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Using cached pip-20.1-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.1
    Uninstalling pip-20.1:
      Successfully uninstalled pip-20.1
  WARNING: The scripts pip, pip2 and pip2.7 are installed in '~/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.1

Then add ~/.local/bin/ to your PATH (e.g. in your ~/.bashrc):

PATH=$HOME/.local/bin/:$PATH

After that you should have a working pip command for Python 2. Or use pip2 / pip2.7 if you want to make sure you're not targeting Python 3.