Debian: Set python 3 as default

Hi,

debian is still delivered with 2.7 as the default version of python. /usr/bin/python is in fact a symlink to the current default versions binary.

The update-alternatives scripts allows to change this.

root@debdev ~# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Nov 24  2017 /usr/bin/python -> python2.7

Check with versions are already installed

root@debdev ~# dpkg -l | grep python
...
ii  python2.7         
...
ii  python3           
...
ii  python3.5         
...
root@debdev ~# ls -l /usr/bin/python*
/usr/bin/python -> python2.7
/usr/bin/python2 -> python2.7
/usr/bin/python2.7
/usr/bin/python3 -> python3.5
/usr/bin/python3.5

In my example Python 2.7 and 3.5 are installed. python3 is a symlink to 3.5

To set python 3.5 as default use the update-alternatives scripts. You can set more alternatives the last number defines the priority. Higher number means higher priority.

root@debdev ~# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
root@debdev ~# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

After setting more then one alternatives you can easily switch the version by

root@debdev ~# update-alternatives --config python

Michael

Advertisment to support michlstechblog.info

3 thoughts on “Debian: Set python 3 as default”

  1. Beware this can break apt! For details, just search stackoverflow.com for “How to update-alternatives to Python 3 without breaking apt?”

    1. Hi Fizz,

      ok, thx for the hint, I realized the prefered way is to use virtual env instead of changing the system default python.
      2.7 is no langer in maintenance so I think debian have to switch to python3 as default.

      Michael

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.