Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu 18.04 "sudo apt-get install python2" results in "E: Unable to locate package python2"

Tags:

python-2.x

In preparation for supporting a Python 2 legacy application I just installed Ubuntu 18.04.5, which includes Python 3 but not Python 2. Pretty much every Python 2 install tutorial website shows the following command for installing Python 2:

sudo apt-get install python2

Upon which I get:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python2

Some sites list these commands first so I tried these as well:

sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo apt-get update
sudo apt-get install python2

This gives the same results as above.

I setup Ubuntu 20.04 on a different computer and installed Python 2 about a month ago and I could swear I used the same commands and at that time it worked. I also remember something about Python 2 being decommissioned at the end of January 2021 (which just passed).

Was the Python 2 pip package taken down? Is there some way I can verify this? If so, is there some special curl command that can still download Python 2 or a website I can download it from?

like image 865
cdahms Avatar asked Feb 06 '26 04:02

cdahms


2 Answers

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

like image 177
cdahms Avatar answered Feb 09 '26 07:02

cdahms


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
like image 34
Tamás Egyed Avatar answered Feb 09 '26 07:02

Tamás Egyed