How to set python2 as my default?

I am trying to figure out how to use update-alternatives to temporally set python2 as my default python interpreter. Currently, using the command:

sudo update-alternatives --config python

reports:

There is only one alternative in link group python (providing /usr/bin/python): /usr/bin/python3
Nothing to configure.

However, I do have python2 and python3 installed and working:

rob@linux044:~$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
rob@linux044:~$ python2
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

Any idea how I could use update-alternatives to temporary set python2 as the default python interpreter? I was thinking:

sudo update-alternatives --install /usr/bin/python python3 /usr/bin/python2 

or something similar should work but I am not sure and I dont want to attempt it and screw everything up.

Hi Circuits...

In a short word, DON'T!
Python 2.x.x and 3.x.x are worlds apart.
If your install uses Python 3.x.x then leave well alone as it could well be used by the OS for other things during bootup and the like.
There is nothing to stop you using Python 2.x.x but expect significant differences between the two.
One simple major difference is Python 2.x.x uses print as a statement/command whereas Python 3.x.x has print() as a function.
Another important one is raw inputting is raw_input() in Python 2.x.x and just input() in Python 3.x.x.
Python 2.x.x input() is NOT the same as Python 3.x.x input() .
There are numerous more differences that you should recode anything you write to suit version 3.x.x as 2.x.x is not being supported after around 2020.

So to reiterate DON'T make python2 your default OR vice-versa!

Yes I am well aware of the differences between py2 and py3 lol I have had to convert a handful of python scripts from 2 to 3 in the past. As far as I know neither the Linux OS or the DOS OS has any dependencies on Python. No I just need to temporarily move from py3 to py2 so that I can compile an older program and I would like to do it with update-alternatives so that I can easily change back after I compile the program.

OK I will take your word for it...

Well if you wish to have Python 2.x.x temporarily you could try copying 'python' to 'python3' in probably the '/usr/bin/' drawer and then copying 'python2' to 'python'; and when finished change back again so that 'python3' becomes python again.
It should see the correct PYTHONPATH but don't quote me on it.

The only problem might be special modules, say for example 'scipy', might not be seen.
It is up to you but I still say DON'T! Even experienced professional programmers would think twice before messing.

EDIT:
You might need to be in 'root' to do this...

For anyone in the future who might have stumbled upon this thread:

The easiest way to switch between Python 3 and Python 2:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 5
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 4

The above will make Python3 the default. Then, to switch to python2:

 sudo update-alternatives --set python /usr/bin/python2

To switch back to python3:

sudo update-alternatives --set python /usr/bin/python3
3 Likes