Are using CentOS 7.7 and Python but you are not able to use Python 3 and still using Python 2.7 version or earlier?
Or In your system information, you are getting python version 2.7.5 which is EOL instead of python 3.6. Then in this article, I will let you know how you can fix this issue on your Linux CentOS 7 version.
How to Install Python3 in CentOS 7 and higher
Python 3 is accessible in the python3 package, which contains the following functions:
yum install python3
Install yum if not installed already on CentOS 7
Prior to CentOS 7.7, it was essential to set up third-party repositories like the IUS repository to make Python 3 available for installation, as the CentOS base repository did not contain a Python 3 package. Fortunately, Python 3 is now included in the base package repository for CentOS 7.7.
[root@centos7 ~]# yum update -y
Install or Update Python 3 on CentOS
Even though the interpreter is python3, python will continue to use the Python 2 interpreter.
The Python Software Foundation has declared Python 2 to be no longer supported, however, Red Hat continues to provide support for Python 2 in RHEL, and CentOS should continue to benefit from that support.
Python 2.7.5, which is included with CentOS, is not officially deprecated, as CentOS will continue to support it throughout the duration of CentOS 7 and beyond. A similar statement may be made about the Python 2.7.5 distribution that comes with Red Hat Enterprise Linux 7.
If you want to obtain Python 3, you can do so by running the following can alternatively obtain it from the CentOS Software Collections repository, which is located at:
yum install centos-release-scl
After that, you can install any revision of Python 3 up to and including 3.6 with:
yum install rh-python35
yum install rh-python36
yum install rh-python37
or you can use the below command to install Python 3 on the CentOS 7 version.
[root@centos7 ~]# yum install -y python3
It’s all done now! Python 3 has been successfully installed. Python 3’s package management PIP is installed simultaneously with the Python 3 package, so we don’t have to worry about it during installation.
Set Python 3 as Default
Use the below command to set Python3 as the default version on the CentOS 7 and upper version of this operating system.
[root@centos7 ~]# alternatives --install /usr/bin/python python /usr/bin/python2 50
[root@centos7 ~]# alternatives --install /usr/bin/python python /usr/bin/python3.6 60
[root@centos7 ~]# alternatives --config python
Wrap Up
That’s all for CentOS7.7 and Python3 installation and verification and how you can set python3 as default instead of Python 2.7.5 version which is EOL.
If you liked our answer then please follow us on Facebook, Twitter and Subscribe to our Newsletter to join a great community of developers around the world. Let us know the questions and answer you want to cover in this blog.
Further Read: