
Python is one of the most popular programming languages in the world. The simple and easy-to-learn syntax makes Python a recognized choice for beginners and experienced developers.
Unlike other Linux distributions, on CentOS 8, Python is not installed by default.
As you may already know, two versions of Python are actively developed. Although Python is well supported and very active, Python 3 is already considered the language of today and the future.
By default, RHEL/CentOS 8 does not have a system-wide python command without a version number to avoid locking users on a specific Python version. Instead, it gives the user the choice to install, configure, and run the specified Python version. System tools such as yum use an internal Python binary file and library file.
This guide will take you to install Python 3 and Python 2 on CentOS 8.
In order to install Python 3 on CentOS 8, run the following command as root or another sudo user:
sudo dnf install python3
To verify the installation process, enter the following command to check the Python version number:
python3 --version
At the time of writing this article, the latest version of Python 3 in the CentOS source repository is "3.6.x":
Python 3.6.8
This command will also install pip.
To run Python, you need to explicitly enter python3 and run pip by entering pip3.
You should like to install the python modules provided by the distribution via yum or dnf. Because in order to run normally on CentOS 8, they have been well supported and tested.
Only use pip in a virtual environment. Python Virtual Environments allows you to install Python modules for individual projects instead of globally.
In this way, you don't have to worry about affecting other Python projects.
Python 3 module packages use python3 as the prefix of their names. For example, to install the paramiko module, you can run:
sudo dnf install python3-paramiko
The Python 2 package is also included in the default CentOS 8 source repository.
To install Python 2, enter the following command:
sudo dnf install python2
Enter the following command to verify the installation process:
python2 --version
The output should look like this:
Python 2.7.15
To execute Python 2, enter python2 and enter pip2 to run pip.
If your application expects to find the python command in the system Path, you will need to create a python command without a version number and set the default version.
To set Python 3 as a system-wide python command, please use the alternatives tool:
sudo alternatives --set python /usr/bin/python3
For Python 2, enter:
sudo alternatives --set python /usr/bin/python2
This alternatives command creates a python soft link pointing to the specified python version.
In your terminal, enter python -version, you can see the default Python version number.
To modify the default version number, please use any of the above commands. If you want to remove the python command without the version number, enter:
sudo alternatives --auto python
In CentOS 8, Python is not installed by default.
To install Python 3, type dnf install python3. To install Python 2, type dnf install python2.
Recommended Posts