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:
2 Answers
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
-
root@debian:~# apt install python-is-python3 Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package python-is-python3 Dec 14, 2020 at 21:51
-
Results of
apt policy python-is-python3
:python-is-python3: Installed: (none) Candidate: 3.8.2-4 Version table: 3.8.2-4 500 500 http://il.archive.ubuntu.com/ubuntu focal/main amd64 Packages
– karelDec 15, 2020 at 4:27
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
Further more, /usr/bin/python is not present on new Ubuntu 20.04 installs (for upgraded systems, /usr/bin/python continues to point to python2). If you need /usr/bin/python to point to python3, install the python-is-python3 package.
python
point topython3
. That would break a lot of legacy homemade python2 scripts still floating around on folks' systems, and would confuse a lot of folks needlessly.python
command either to start the system default Python 3 interpreter or how to start the system default Python 3 interpreter with a different command (a command different frompython
) in order to be able to use Python 2 alongside Python 3. Let's assume that the OP in this question already knows that Python 2 is still supported in 20.04 from his own screenshot.