Run these commands to ensure your repositories are up to date before installing
Copysudo apt update
sudo apt upgrade
sudo apt install python2.7
Then to install pip for python 2:
Copysudo apt install python-pip
Answer from Spiff on Stack OverflowRun these commands to ensure your repositories are up to date before installing
Copysudo apt update
sudo apt upgrade
sudo apt install python2.7
Then to install pip for python 2:
Copysudo apt install python-pip
As my comment has solved the issue, I will develop it a little more in this answer for further reference.
Try using aptitude, it better manage conflicting packages for you:
Copysudo aptitude install python-minimal
Reference: https://askubuntu.com/a/451078/1006720
First, install some dependencies:
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Then download using the following command:
version=2.7.13
cd ~/Downloads/
wget https://www.python.org/ftp/python/$version/Python-$version.tgz
Extract and go to the directory:
tar -xvf Python-$version.tgz
cd Python-$version
Now, install using the command you just tried, using checkinstall instead to make it easier to uninstall if needed:
./configure
make
sudo checkinstall
Change version to whichever version you need (version=2.7.1 or version=3.6.0, for example).
Unless you really have a burning desire to compile it yourself, the preferred way is to use the DeadSnakes PPA to install versions of Python that aren't included by default:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python2.7
Other versions, such as python2.4 or python3.6, etc. are also available.
Python 2.7.18 is installed yet only Python 2.7.17 only shows up with Python2 -V
What is the safest way to work with Python 2 on Ubuntu 24.04?
Trying to remove python 2.7 on ubuntu 18.04.
I suggest NOT messing with removing Python unless you really know what you are doing.
18.04 includes python3 - it is called.... python3 so you can have both 2.7 and 3.0 installed with No hassle..
So you may be going about this the totally wrong way.
Good Luck.
More on reddit.comVideos
Hi everyone,
I'm using a laptop with Ubuntu and I have just installed Python 2.7.18 using this tutorial https://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/ . When I execute Python2 -V, it shows me Python 2.7.17 as the version of Python installed. However, if I execute Python2.7 -V, it shows me Python 2.7.18 as the Python version (see screenshot drive link to see the issue). What does this mean? In my (other) Windows laptop, when I execute Python2 -V, it shows me Python 2.7.18 so why doesn't it happen here in my Ubuntu laptop? Thanks in advance.
Screenshot link: https://drive.google.com/file/d/18xlyZU8eEjBb4U90RwLq8g_oKUxCO_ud/view?usp=sharing
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!
Python 2 is no longer installed by default in fresh installations of Ubuntu 18.04 and later. Don't remove python3 from Ubuntu 18.04 and later or else Ubuntu Software, the terminal and many other apps that are installed by default will stop working. If you removed Python 3 and now Ubuntu Software, terminal and other applications don't work follow the instructions in this answer to reinstall it and get all applications working again.
To install Python 2.7 in Ubuntu 18.04 and later open the terminal and type:
sudo apt install python2.7
To start the Python 2.7 interpreter run this command:
python2.7
To start the Python 3 interpreter run this command:
python3
Either way the Python interpreter will show a version message when it is started that shows what version of Python you are running.
1) To install Python 2 version on Ubuntu 18.04 open up terminal and enter:
sudo apt install python-minimal
or
sudo apt install python2.7
Check version:
python --version
2) If still python 3+ updated list of Python alternatives to perform a switch between any python version is to run:
update-alternatives --config python
Example:
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 2 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode
and select an appropriate version using selction integer as shown above.
3) If you see: update-alternatives: error: no alternatives for python. Run:
ls /usr/bin/python*
Example output:
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.5
Next, update the Python alternatives list for each version you whish to use with priority 1 and 2:
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
Then run again update-alternatives --config python and select an appropriate version..