6

We knew Ubuntu 20.04 will set python 3 as default python, but after upgrade from 18.04 to 20.04, I found my default python version is 2.7.18rc1 not python3:

my system version and python version

muru
  • 207,228
Rui Cai
  • 71

2 Answers2

2

Running the python command in the terminal starts the Python 2 interpreter if Python 2 is installed, as it is in your Ubuntu 20.04. In Ubuntu 20.04 you can also start Python 3 which is preinstalled with the python command by installing the python-is-python3 package.

sudo apt install python-is-python3

You can also start the Python 3 interpreter from the terminal the usual way by running python3

karel
  • 122,292
  • 133
  • 301
  • 332
1

Apart from a solution with installing python-is-python3 (mentioned in comment by Stephan Boston), there's one more using update-alternatives or using GUI galternatives, which would work not only with python, but any tool and any number of its versions.

Let's start at the very beginning. I have newly installed Ubuntu 20.04 and in /usr/bin don't even have sole python, but only python3 and python2. You type:

# update-alternatives --install /usr/bin/python python /usr/bin/python3 10
# update-alternatives --install /usr/bin/python python /usr/bin/python2 9
# update-alternatives --config python

After typing the last command you would be asked to choose the prefered version manually or leave the selection in auto mode, where in our example python3 has higher priority 10 than 9 of python2, so python3 would be default.

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

If I've typped 1:

$ python --version
Python 2.7.18rc1

I've changed my mind and in update-alternatives --config python selected 0 for auto (bidding for the highest priority):

$ python --version
Python 3.8.2