How to install Python on CentOS 8

As you know, there are two versions of Python under active development. Although Python 2 before use and well supported, but Python 3 is considered to be the future of the language.

By default, RHEL / CentOS 8 does not have a system-level command python to avoid lock users to a specific python version. Instead, it lets the user choose to install, configure and run a specific version of Python. System utilities such as yum like to use internal Python binaries and libraries.

This guide will walk you through the installation on CentOS 8 Python 3 and Python 2.

Python 3 mounted on CentOS 8

To install Python 3 on CentOS 8, run the following command in the terminal as root or sudo user:

sudo dnf install python3

To verify the installation, enter the following command to check the version of Python:

As of this writing, CentOS repositories available in the latest version of Python 3 is the "3.6.x":

The command also installs pip.

To run Python, you need to explicitly enter and run python3 pip enter pip3.

You should always prefer to use python module yum or dnf install the release version provided, because they have supported and has been tested to work on CentOS 8. Pip used only in a virtual environment. Python virtual environment that allows you to install Python module in an isolated location-specific projects, rather than the overall installation. This way, you do not have to worry about affecting other Python projects.

Name Python 3 module packages with "python3" as a prefix. For example, to install paramiko module should run:

sudo dnf install python3-paramiko

Mounted on CentOS 8 Python 2

Python 2 software package also included in the default CentOS 8 repository.

To install Python 2, enter the following command:

sudo dnf install python2

Verify the installation by typing the following command:

The output should be as follows:

Python 2.7.15

To execute Python 2, enter python2, and then run the pip and enter pip2.

How to install Python on CentOS 8

Set the default Python version (Unversioned Python command)

If you want to find an application in python command system path, you need to create the python command Unversioned and set the default version.

To set a non-Python 3 version of the python command system-wide, use Alternatives utility:

sudo alternatives --set python /usr/bin/python3

For Python 2, input:

sudo alternatives --set python /usr/bin/python2

Alternatives to the specified command to create a version of python symlink python.

Type python --version in a terminal, you should see the default version of Python.

To change the default version, use one of the above command. If you want to delete unprotected python version control command, enter:

sudo alternatives --auto python

How to install Python on CentOS 8

to sum up

In CentOS 8, Python is not installed by default.

To install Python 3, type dnf install python3, then install python 2, type dnf install python2.

If you have any questions or feedback, please post a comment below.

Guess you like

Origin www.linuxidc.com/Linux/2019-11/161444.htm