Python is the most growing programming language in many fields such as software development, machine learning, AI, and Deep Learning in this world.
Python is suitable for all users, beginners as well as experienced developers due to its simplicity and easy to learn syntax.
It is not installed on CentOS 8 environment by default.
As we know that python has two different versions python 2 and python 3.
Python3 is using the latest python programming language.
But, most of the applications still support the python2 version.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to install Python packages on CentOS Systems.
In this context, we shall look into how to install python2 and python3 on your CentOS 8 Linux environment.
How to install Python3 on CentOS 8 ?
To begin, ensure that you log into the system as a root user or should have to run the 'sudo' command privileges.
Python has two versions python2 and python3.
If you want to install both on your system then, you need to install them explicitly.
i. Open the terminal from your desktop.
ii. To access the terminal, select the 'Activities' section and then from the left sidebar click on the terminal icon in CentOS 8 distribution.
iii. Now, type the 'su' command on the terminal and enter the administrative password to log in as a root user.
iv. You can install python3 from the CentOS 8 yum or dnf repositories, type the following command on the terminal with root privileges to install the python3:
# dnf install python3
Type 'y' and then hit the 'Enter' key in order to complete the installation python3.
v. To verify the installation, run the below-mentioned command to check the installed version:
# python3 –version
How to install python3 packages ?
If you want to install python packages then, use python3 as a prefix with the name of packages as follows:
# dnf install python3-pip
The above command will install the remaining pip packages on your system.
How to run python3 and print 'hello'?
To run the python3, type the ‘python3’ on the terminal and print 'hello' on the screen:
>>> print (‘hello’)
To exit from the current displaying python3 environment, type the following command on the terminal:
>>> quit ()
How to install Python2 on CentOS 8 ?
You can also install ‘python2’ packages from the default CentOS 8 repository by using the following command:
# dnf install python2
To check the installed python2 version, use the following command:
# python2 --version
How to use unversioned python commands (Set python default version) ?
You can use the following unversioned python commands, you can set python2 and python3 as the default version.
1. For python3, use the following command:
# alternatives --set python /usr/bin/python3
2. For python2, type the following command:
# alternatives --set python /usr/bin/python2
Now, enter the following command on the terminal to check the default set python version on your system:
# python --version
To set or change the python default version, you can use any above-mentioned commands.
If you don't want to use the explicitly above command then, use the command as follows:
# alternatives --auto python
[Need urgent assistance to install missing packages on CentOS system? We are available. ]