Ubuntu 20.04
Sponsored Link

Python : Install2020/07/27

 
Install Python.
[1] Install Python 3.
root@dlp:~#
apt -y install python3
root@dlp:~#
python3 -V

Python 3.8.2
# verify to run test script

[root@dlp ~]#
echo -e "import sys\nprint(sys.version)" > python3_test.py

[root@dlp ~]#
python3 python3_test.py

3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0]
[2] If you'd like to install Python 2, Install like follows.
root@dlp:~#
apt -y install python2
root@dlp:~#
python2 -V

Python 2.7.18rc1
[3] If you installed both Python 3 and Python 2 and you'd like to use either of one of them as a [python] command, configure like follows.
root@dlp:~#
which python3

/usr/bin/python3
root@dlp:~#
ll /usr/bin/python3*

lrwxrwxrwx 1 root root       9 Mar 13 21:20 /usr/bin/python3 -> python3.8*
-rwxr-xr-x 1 root root 5457536 Apr 28 00:53 /usr/bin/python3.8*

root@dlp:~#
which python2

/usr/bin/python2
root@dlp:~#
ll /usr/bin/python2*

lrwxrwxrwx 1 root root       9 Mar 13 21:31 /usr/bin/python2 -> python2.7*
-rwxr-xr-x 1 root root 3694632 Apr  7 21:05 /usr/bin/python2.7*

root@dlp:~#
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1

root@dlp:~#
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2

root@dlp:~#
update-alternatives --config python

There are 2 choices for the alternative python (providing /usr/bin/python).

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

# select a number
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/python3.8 to provide /usr/bin/python (python) in manual mode

root@dlp:~#
python -V

Python 3.8.2
Matched Content