[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedJuly 10, 2023

How to install Python 3 in CentOS 7.

How To Install Python 3 In CentOS 7.

This tutorial will guide you through installing Python 3 on a CentOS 7 system using the Software Collections (SCL) alongside the distribution default Python version 2.7. We will also show you how to create a Python virtual environment.

 

Enable Software Collections (SCL)

To enable SCL, you need to install the CentOS SCL release file. It is part of the CentOS extras repository and can be installed by running the following command:

sudo yum install centos-release-scl

 

Installing Python 3 on CentOS 7

Now that you have access to the SCL repository, you can install any Python 3.x version you need. Currently, the following Python 3 collections are available:

  • Python 3.3

  • Python 3.4

  • Python 3.5

  • Python 3.6

In this tutorial, we will install Python 3.6, which is the latest version available at the time of writing. To do so type the following command on your CentOS 7 terminal:

sudo yum install rh-python36

 

Using Python 3

Once the package rh-python36 is installed, check the Python version by typing:

python --version
Python 2.7.5

You will notice that Python 2.7 is the default Python version in your current shell.

To access Python 3.6 you need to launch a new shell instance using the Software Collection scl tool:

scl enable rh-python36 bash

What the command above does is calling the script /opt/rh/rh-python36/enable, which changes the shell environment variables.

If you check the Python version again, you’ll notice that Python 3.6 is the default version in your current shell now.

python --version
Python 2.7.5

It is important to point out that Python 3.6 is set as the default Python version only in this shell session. If you exit the session or open a new session from another terminal Python 2.7 will be the default Python version.

 

Installing Development Tools

Development tools are required for building Python modules. To install the necessary tools and libraries type:

sudo yum groupinstall 'Development Tools'

 

Creating a Virtual Environment

Python Virtual Environments allows you to install Python modules in an isolated location for a specific project, rather than being installed globally. This way, you do not have to worry about affecting other Python projects.

The preferred way to create a new virtual environment in Python 3 is by executing the venv command.

Let’s say you want to create a new Python 3 project called my_new_project inside your user home directory and matching virtual environment.

First, create the project directory and switch to it:

mkdir ~/my_new_projectcd ~/my_new_project

Activate Python 3.6 using the scl tool:

scl enable rh-python36 bash

From inside the project root run the following command to create a virtual environment named my_project_venv:

python -m venv my_project_venv

To start using the virtual environment, activate it by typing:

source my_project_venv/bin/activate

After activating the environment, the shell prompt will be prefixed with the name of the environment:

(my_project_venv) user@host:~/my_new_project$

Starting with Python 3.4, when creating virtual environments pip, the package manager for Python is installed by default.

 

Conclusion

You should now have Python 3 programming environment set up on your CentOS 7 machine, and you can start developing your Python 3 project.

Keep reading
How to Enable and Disable Root User Account in Ubuntu
May 30, 2023

How to Enable and Disable Root User Account in Ubuntu

How To Enable And Disable Root User Account In Ubuntu This tutorial explains how to enable and disable the root user account in Ubuntu Linux. As a new Ubuntu user, you may wonder how to log in to your Ubuntu system as a root user or what is the default root password. In Ubuntu Linux,…

Read article
How to Add and Delete Users on Debian 9.
May 30, 2023

How to Add and Delete Users on Debian 9.

How To Add And Delete Users On Debian 9. This tutorial explains how to add and remove users on Debian 9. Debian, as well as all other Linux distributions, is a multi-user operating system. Each user can have different permission levels and specific settings for various command-line and GUI…

Read article
How To Set or Change Timezone on Debian 9.
May 30, 2023

How To Set or Change Timezone on Debian 9.

How To Set Or Change Timezone On Debian 9. Using the correct timezone is important for many systems related tasks and processes. For example, the cron daemon uses the system’s timezone for executing cron jobs and the timestamps in the log files are based on the same system’s timezone. The system’s…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00