After searching the Ubuntu packages, it seems that for some odd reason for Ubuntu 20.04 the name of the Python 2 package is python2 but for Ubuntu 18.04 there is no package named python2. It seems that for Ubuntu 18.04 by running:
sudo apt-get install python-pip
This installs both pip for Python 2 and Python 2 itself, so this seems to be the best option
Answer from cdahms on Stack Overflowpython 2.x - Ubuntu 18.04 "sudo apt-get install python2" results in "E: Unable to locate package python2" - Stack Overflow
apt - How to install python2.7-dev package on vanilla debian 12? - Unix & Linux Stack Exchange
Is there any way to get Python 2 on Debian 12?
Python 2.7.18 is installed yet only Python 2.7.17 only shows up with Python2 -V
Videos
Running Mint 22 and I need to install python 2.7 because I'm trying to mod a leapster. I haven't found a way that works yet. If anyone reading this knows how to install SPECIFICALLY python 2.7, please let me know as soon as you can. Thanks!
After searching the Ubuntu packages, it seems that for some odd reason for Ubuntu 20.04 the name of the Python 2 package is python2 but for Ubuntu 18.04 there is no package named python2. It seems that for Ubuntu 18.04 by running:
sudo apt-get install python-pip
This installs both pip for Python 2 and Python 2 itself, so this seems to be the best option
This was the only method that allowed me to install Python 2 (2.7.9) on a Ubuntu 20.04 machine:
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
sudo tar xzf Python-2.7.9.tgz
cd Python-2.7.9
sudo ./configure --enable-optimizations
sudo make altinstall
You can still install Python 2.7 from Debian 11. Mixing releases is typically decried as a bad idea, but that is mostly in the context of adding a newer release; adding an older (still-supported) release is much less error-prone, as long as you keep an eye on any packages apt wants to remove.
Add a file, /etc/apt/sources.list.d/bullseye.list, containing
deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://security.debian.org bullseye-security main
Run sudo apt update, and you will be able to install python2.7-dev.
As you are probably aware, maintaining Python 2-based projects is becoming increasingly difficult, and the above won’t be a viable approach once Debian 11 is no longer supported (some would argue it already isn’t viable).
The PPA Approach
While Stephen's answer is certainly viable until Bullseye is no longer supported. I believe this approach will survive until the various python versions are removed from the PPA. Adding this PPA or Personal Package Archive, or any for that matter is relatively easy.
The PPA Specifically for Python
The Dead Snakes Personal Package Archive contains packaged versions of Python all the way back to 2.3. Add it with: sudo add-apt-repository ppa:deadsnakes/ppa
Note that these are made to work with Ubuntu, and since that's a Debian derivative:
The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.
See also: Install newer & older versions of python on debian?. Read Gilles' answer from 8 years ago that's still quite valid.