How To Install Python 3 on CentOS 7

Published: December 1, 2025 (Updated: Dec 1, 2025)

Enjoying this content? Subscribe to the Channel!

Master Python 3 on CentOS 7: Installation and Virtual Environment Setup


Welcome to Darren’s Tech Tutorials!

If you’re running a CentOS 7 server and ready to dive into modern programming, installing Python 3 is your critical first step. Python 3 is the backbone for countless applications, automation scripts, and development projects.

In this comprehensive guide, we’ll walk you through installing the stable Python 3.6 release, securing all the necessary development tools, and—most importantly—setting up a clean, isolated virtual environment (venv) to keep your projects organized and separate from your system files.

Let’s get your CentOS 7 box ready for serious coding!


Note: All commands referenced in this tutorial are available for easy copy/pasting on our website: https://darrenoneill.eu/?p=317

P.S. Need a quick Linux reference? Grab our free Linux cheat sheet here: http://eepurl.com/dkRNM9


Step 1: Prepare Your CentOS 7 Server

Before we install Python, we need to ensure your system is fully updated and has the necessary utilities to handle new packages and compilation tasks.

Open your terminal and follow these steps:

1. Update the System

Always start with a full system update to ensure you have the latest stable packages.

sudo yum update

If prompted, enter your user password and accept any pending updates.

2. Install YUM Utilities

We need yum-utils to handle certain repositories smoothly.

sudo yum install yum-utils

3. Install Development Tools

This group of tools is essential, as it includes compilers and libraries needed to build and install Python dependencies correctly.

sudo yum group install "Development Tools"

When prompted, press Y to confirm the installation. This step may take a few minutes.

Step 2: Install Python 3.6 and Essential Packages

CentOS 7 typically uses an older Python version by default. To get a stable, upstream version of Python 3.6, we need to add a trusted third-party repository.

1. Add the Python 3.6 Repository

We will use the IUS Community Project repository, which offers updated versions of software for RHEL/CentOS systems.

sudo yum -y install https://centos7.iuscommunity.org/ius-release.rpm

The -y flag tells YUM to automatically accept the installation without prompting you.

2. Install Python 3.6

Now we can install Python 3.6 itself, along with the necessary pip package manager and development libraries.

Install Python 3.6

sudo yum install python36u

Install Pip (Python Package Installer)

Pip is crucial for managing external Python libraries and packages.

sudo yum install python36u-pip

Install Development Libraries

These libraries are often required when compiling native Python extensions.

sudo yum install python36u-devel

Step 3: Verify the Installation

To ensure everything installed correctly, let’s check the version number.

In your terminal, run:

python3.6 -V

You should see output confirming the version installed, such as:

Python 3.6.x

Perfect! You now have a working version of Python 3.6 on your CentOS server.

Step 4: Create and Activate Your Virtual Environment (VENV)

This is perhaps the most important step for professional development. A virtual environment allows you to isolate project-specific dependencies. This means if one project needs Django 2.0 and another needs Django 4.0, they won’t conflict with each other or your system’s core files.

1. Set Up the Environment Directory

First, let’s create a central location for all your virtual environments. Ensure you are in your user’s home directory (cd ~).

mkdir environments
cd environments

2. Create the Virtual Environment

We will use the built-in venv module. We’ll name our new environment my_env.

python3.6 -m venv my_env

3. Activate the Environment

To start using this isolated environment, you must activate it.

source my_env/bin/activate

Success Check: You know the environment is active when you see the environment name ((my_env)) prepended to your terminal prompt!

Step 5: Write and Run Your First Python Program

Now that your environment is active, let’s create the classic “Hello World” program.

1. Create the File

Use a text editor like vi (or nano if installed) to create your file.

vi hello_world.py

Press i to enter INSERT mode.

2. Write the Code

Type the following line:

print("Hello World!")

Press ESC, then type :wq and hit enter to save and quit.

3. Run the Program

Since you are inside your virtual environment, you can now simply use the generic python command (which points directly to your Python 3.6 installation within the venv).

python hello_world.py

Output:

Hello World!

Congratulations! You have successfully installed Python 3.6, set up a best-practice virtual environment, and run your first program on CentOS 7.

Conclusion

Getting Python 3 installed correctly on a server operating system like CentOS 7 can sometimes be tricky, but by following these steps, you’ve ensured you have a clean, modern, and robust environment ready for any development challenge.

Now that you have Python 3.6 up and running, the real fun begins! Start installing packages using pip and building your projects right within your isolated my_env.

Did this tutorial help you get set up? If so, please hit that like button, subscribe to Darren’s Tech Tutorials for more clear guides, and leave a comment below if you ran into any issues—we’re here to help!

Happy coding!