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
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-*.

5
  • 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 8 '20 at 14:22
  • Actually, found a hack 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 8 '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 8 '20 at 21:56
  • 1
    @JohnHeyer : You have posted an XY problem. The solution to the question you should have asked is here. – Eric Towers May 8 '20 at 21:57
  • geolite is free, while geoip2 requires a paid subscription. – John Heyer May 11 '20 at 8:43
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.