How To Install Python 3 On CentOS 7 Using SCL

Introduction

Python is an incredible programming language that is ideal for both beginners and well-versed developers. The language is versatile which means it can be used to perform various functions such as building games, writing small scripts, creating algorithms for machine learning, analyzing data, developing websites, and more.

Some of the most popular websites and applications developed using Python include DropBox, YouTube, Quora, Reddit, Pinterest, and Instagram.

This tutorial will show you how to install the latest version of Python on your CentOS 7 system. The installation will utilize the Software Collections (SCL) and distribution default Python 2.7. We’ll also help you learn some basics and create a virtual environment for Python to streamline its usage.

Ready? Let’s get started!

Step 1
Enabling Software Collections (SCL)

The first thing when installing Python on CentOS 7 is enabling the Software Collections. The Software Collection is a reliable, community project designed to allow developers to install, build, and utilize numerous software versions on a single system without compromising the performance of the system default modules.

When the SCLs are enabled they grant you unfettered permissions to use the latest version of services and programming languages that may not be present in the main repositories.

Run the command below to install the release files for SCL. The release file is a component of  CentOS additional repository.

$ sudo yum install centos-release-scl

Step 2
Installing Python 3

You have enabled the SCL and should be able to access the Software Collections repository. This means you can implement any version of Python 3. At the time of writing Python 3 collection had the following 3.x versions:

  • Python 3.6
  • Python 3.5
  • Python 3.4
  • Python 3.3

Our tutorial will focus on Python version 3.6. To install this Python version, run the command below:

$  sudo yum install rh-python36

The application will not take long to install. Once the installation is complete, you can now proceed with the usage of Python.

Step 3
Using Python 3

First, run the command below to verify the version of Python 3:

$ python --version

This will give you the output below:

Python 2.7.5

This is because Python 2.7 manifests as the default application on the current shell. However, we installed Python 3.6 and that is what we intend to use. Now to access this version, we should make use of the SCL tool to launch a different shell instance:

$ scl enable rh-python36 bash

The command above will call /opt/rh/rh-python36/enable; a script that changes the variables of a shell environment. Now, if you verify your Python version once again:

$ python --version

You will get the output below:

$ Python 3.6.3

However, this does not change the core settings. Python 3.6 will function as a main Python version in the current shell environment. In case you exit the current shell session and enter a new one, Python 2.7 will still manifest as the default version.

Step 4
Installing The Python Development Tools

Development tools help you build Python Modules, Now, run the command below to install all the required libraries and tools:

$ sudo yum groupinstall 'Development Tools'

Step 5
Creating Python Virtual Environment

The Python virtual environment permits you to configure Python packages in a secure location. The environment offers unprecedented control over your system for Python projects. It ensures that every project has its own dependencies and that it will not interfere with other projects.

First, fashion a new project directory, then switch to the directory:

$ mkdir ~/my_new_project
$cd ~/my_new_project

Next, run the command below to enable Python:

$ scl enable rh-python36 bash

Now, run the command below from within the new Project root to fashion a new environment called my_project_venv:

$ python -m venv my_project_venv

Execute the command below to enable the new virtual environment:

$source my_project_venv/bin/activate

Once the virtual environment is activated, your shell prompt should be prefixed with the title of the virtual environment.

$ (my_project_venv) user@host:~/my_new_project$

The prefix indicates that the Python virtual environment my_project_venv is currently active. This means that if you create new programs in this environment, they will only utilize the settings and packages specific to this environment.

By now, the Python virtual environment is set and ready to use.

Conclusion

That’s it! You have successfully installed Python 3.6 on your CentOS system and it should be easy to utilize  Python programming language to develop a new application.

Check out these top 3 Linux hosting services

HostArmada
$1.79 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
$2.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How To Install Python Pip On CentOS 7

This tutorial will show you how to install Pip on CentOS 7 using the yum package
2 min read
David Malcom
David Malcom
Author

How to install Django on a CentOS 7 VPS or Dedicated Server

When building a website, similar components are required, and you do not have to
3 min read
Mark Armistead
Mark Armistead
Author

How To Install CachetHQ On a CentOS 7 VPS or Dedicated Server

This tutorial will help you install CacheHQ on your CentOS 7 server. CacheHQ is
5 min read
David Malcom
David Malcom
Author

How to Create a Dynamic Web App with Django

Overview As a “batteries included” framework, Django
3 min read
Mark Armistead
Mark Armistead
Author
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top