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 OverflowAfter 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
Need to install python 2. How do I accomplish this?
What is the safest way to work with Python 2 on Ubuntu 24.04?
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?
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!
Hi all! I just started a new job that is having me analyze/write code in Python 2. The reason it is Python 2 and not Python 3 is because we are supporting older systems that require it, and our code must be backwards compatible with these systems.
With that said, the workstation they've supplied me is running Ubuntu 24.04, and I'm at wits end as to how I can SAFELY run Python 2 code on it. From what I've gathered, recent versions of Ubuntu depend on Python 3 packages so it isn't as simple as adding a legacy apt repo and installing Python 2 - it would break my OS.
So, the question remains: How can I safely work with Python 2 without bricking my OS? Do I need to containerize or use virtualization? Thank you!
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.