Python version switch manager

Ramesh Babu Chayapathi
2 min readNov 4, 2020

--

https://www.dataquest.io/wp-content/uploads/2022/01/python-virtual-envs1.webp

The objective of this tutorial is to provide the reader with an easy to follow way of switching between alternative Python versions on Ubuntu 20.04 Focal Fossa Desktop/Server.

In this tutorial you will learn:

  • How to check installed Python versions
  • How to switch between alternative Python versions

How to switch between alternative Python Versions step by step instructions.

step 1 First step is to check what python versions are available on your Ubuntu system. To do so execute the following command:

$ ls /usr/bin/python*
/usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.7 /usr/bin/python3.7m /usr/bin/python3.8 /usr/bin/python3-futurize /usr/bin/python3m /usr/bin/python3-pasteurize

Step 2 Next, check if you already have some python alternatives configured. To do so run:

sudo update-alternatives --list python
update-alternatives: error: no alternatives for python

Step 3 In this step we are going to set two Python alternatives, namely it will by Python2 and Python3 alternative. Execute the following commands:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2

Step 4 Confirm that both alternatives are ready to be used:

$ sudo update-alternatives --list python
/usr/bin/python2
/usr/bin/python3

Step 5 Change to alternative python version. For example to change to Python 2 execute the following command:

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3 2 auto mode
1 /usr/bin/python2 1 manual mode
2 /usr/bin/python3 2 manual mode

Press to keep the current choice[*], or type selection number: 1

Enter selection number. In this case to switch to Python version 2 we enter the 1 selection number.

Step 6 Check your python version:

$ python -V
Python 2.7.17

To switch to Python 3 alternative repeat Step 5 and enter the selection number appropriate to your desired python version.

--

--

No responses yet