CentOS 7 ships with Python 2.7.5 which is a critical part of the CentOS base system. SCL will allow you to install newer versions of python 3.x alongside the default python v2.7.5 so that system tools such as yum will continue to work properly. In order to enable SCL we need to install the CentOS SCL release file.
IntroductionIn this tutorial we’ll be learning how to install Python 3.6 and Python 3.7 on a server running Centos 7.Python is a general purpose object oriented programming language that’s been growing in popularity at an incredible rate.Not only has it been popular for it’s use in a wide range of areas, but it is also one of the easiest languages to learn. It’s a great programming language for beginners and experienced developers. It’s versatile and fast to learn and implement.Some of the most popular applications you’ve heard of are written in Python – like Google, DropBox, YouTube, Quora, Instagram, Pinterest, Spotify, Reddit, BitTorrent, to name a few.On top of all that, it’s also seen an explosive growth with the increasing rise of machine learning and AI. OverviewCentOS 7 already comes with a pre-installed version of Python, unfortunately it’s much older, so we’ll have to install the latest version ourselves.In this tutorial we’ll install Python 3 using two methods. The reason for this is that the latest Python version is not always available in Yum repositories, and versions from repositories are pre-compiled, so we have less control over them.In the first method we’ll install the latest Python version available from a repository, and in the second method we’ll install the latest Python version by compiling it ourselves.
Method #1 – Installing Python 3.6 on Centos 7 from a RepositoryThis is the easier method to install Python on your machine.For this, we’ll use. SCL is a community project that allows us to install multiple versions of software on the same system, without affecting default packages.
By using SCL we have access to newer versions of packages that aren’t available in the core repositories.CentOS 7 comes with Python 2.7.5 built-in, which is critical to CentOS. By installing different versions of Python alongside the default v2.7.5, we won’t affect system tools such as yum, so they’ll continue to work properly. Step 1 — Install SCL Release FileTo enable SCL we’ll have to install the CentOS SCL release file. To do this run. Python 3.6.3Do keep in mind that Python 3.6 is the default Python version only in this shell session.
If you exit the session, and open a new one in the terminal, then the default version will be v2.7.5. Method #2 – Compiling Python 3 from Source CodeThis method of installing Python is the more difficult approach, and it will take a bit longer. An advantage to this is that you’ve got more control over it.Please keep in mind that Yum will not know that you’ve installed a software if you manually compiled the source code. That means that no updates will be available if you’ve manually installed it. Step 1 — Install PrerequisitesBefore installing Python, we’ll need to install the necessary tools and libraries to compile and install programs on your system. To do install these prerequisites, run the following comand.
Python is a powerful programming language. It is very friendly and easy to learn. At writing time of this article Python 3.7.3 latest stable version is available to download and install. This tutorial will help you to install Python 3.7.3 on your CentOS, Red Hat & Fedora operating systems. Step 1 – RequirementsThis Python installation required GCC compiler on your system.
Login to your server using ssh or shell access. Now, use the following command to install prerequisites for Python before installing it. Yum install gcc openssl-devel bzip2-devel libffi-devel.
Read:Step 2 – Download Python 3.7Download Python using the following command from the Python official site. You can also download the latest version in place of specified below.
Cd /usr/srcwget extract the downloaded package. Tar xzf Python-3.7.3.tgzStep 3 – Install Python 3.7Use below set of commands to compile Python source code on your system using altinstall. Cd Python-3.7.3./configure -enable-optimizationsmake altinstallmake altinstall is used to prevent replacing the default python binary file /usr/bin/python.Now remove downloaded source archive file from your system rm /usr/src/Python-3.7.3.tgzStep 4 – Check Python VersionCheck the latest version installed of python. Use command python3.7 instead of just python. Python3.7 -VPython 3.7.3.