Table of Contents

Change default python version

Test current default version

pi@idefix03 ~ $ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Check installed versions

pi@raspi: $ ls -l /usr/bin/python*

lrwxrwxrwx 1 root root       7 Mar  4  2019 /usr/bin/python -> python2
lrwxrwxrwx 1 root root       9 Mar  4  2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 2984816 Oct 11  2019 /usr/bin/python2.7
lrwxrwxrwx 1 root root       9 Mar 26  2019 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 4275580 Jan 22  2021 /usr/bin/python3.7
lrwxrwxrwx 1 root root      36 Jan 22  2021 /usr/bin/python3.7-config -> arm-linux-gnueabihf-python3.7-config
-rwxr-xr-x 2 root root 4275580 Jan 22  2021 /usr/bin/python3.7m
lrwxrwxrwx 1 root root      37 Jan 22  2021 /usr/bin/python3.7m-config -> arm-linux-gnueabihf-python3.7m-config
lrwxrwxrwx 1 root root      16 Mar 26  2019 /usr/bin/python3-config -> python3.7-config
lrwxrwxrwx 1 root root      10 Mar 26  2019 /usr/bin/python3m -> python3.7m
lrwxrwxrwx 1 root root      17 Mar 26  2019 /usr/bin/python3m-config -> python3.7m-config

List configured alternatives

pi@raspi: $ update-alternatives --list python
update-alternatives: error: no alternatives for python

Configure alternatives

pi@raspi:$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
pi@raspi:$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2

List alternatives again

pi@raspi:$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.7

Select alternative

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

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

Press <enter> to keep the current choice[*], or type selection number:

Remove alternative

pi@raspi: $ update-alternatives --remove python /usr/bin/python2.7