Python (Scripting) - Configure the "python" command to invoke the "python3" command

Let's say the python --version command returns version 2 of Python.

python --version

Python 2.7.5


And the python3 command returns version 3 of Python.

python3 --version

Python 3.6.8


This is because the python command is most likely symbolically linked to version 2.x of Python, which can be seen like this.

ls -l | grep /usr/bin/python

lrwxrwxrwx. 1 root root 7 Mar  7 23:31 /usr/bin/python -> python2

ls -l | grep /usr/bin/python2

lrwxrwxrwx. 1 root root 9 Mar  7 23:31 /usr/bin/python2 -> python2.7


You do not want to change this symbolic link, as various CentOS commands, such as yum, expect Python2.

The alias command can be used so that the python command invokes python3. For example, if John Doe wants the python command to invoke python3, the following would be added to /home/john.doe/.bash_profile.

IMPORTANT - This would need to be done for each user on the system, including root

alias python=python3
export alias


Now, after John Doe signs out and then back in, going forward, the python --version command should invoke version 3 of Python.

python --version

Python 3.6.8



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter ad884 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |