Install Python 3 on CentOS 7

28/12/2020
In this article, I will show you how to install Python 3.x, mainly Python 3.4, Python 3.5, Python 3.6 along with PIP for Python 3.4, Python 3.5, and Python 3.6 respectively on CentOS 7. Let’s get started.

Adding Package Repository

Python 3 is not installed by default in CentOS 7. Python 3 is not available in the official package repository of CentOS 7 as well. But we can add Inline Upstream Stable (IUS) package repository on CentOS 7 to install Python 3.

First update the yum package repository cache of your CentOS 7 machine with the following command:

$ sudo yum makecache

The yum package repository cache should be updated.

Now install yum-utils package with the following command:

$ sudo yum install yum-utils

Now press y and then press <Enter> to continue.

yum-utils should be installed.

Now add the IUS package repository with the following command:

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

Now press y and then press <Enter> to continue.

IUS package repository should be added.

Now update the yum package repository cache again with the following command:

$ sudo yum makecache

The yum package repository cache should be updated.

Now you’re ready to install Python 3.x.

Installing Python 3.4 and PIP for Python 3.4:

Only Python 3.4:

If you want to install only Python 3.4, not PIP for Python 3.4, run the following command:

$ sudo yum install python34u

Press y and then press <Enter> to continue.

You may be asked to accept the GPG key, press y and then press <Enter> to continue.

Python 3.4 should be installed.

Python 3.4 Including PIP for Python 3.4:

If you want to install Python 3.4 and PIP for Python 3.4, run the following command:

$ sudo yum install python34u python34u-pip

Now press y and then press <Enter> to continue.

Now press y and then press <Enter> to continue.

Python 3.4 and PIP for Python 3.4 should be installed.

Now you can check whether Python 3.4 is installed correctly with the following command:

$ python3.4 -V

As you can see, it is installed and working correctly.

You can also check whether PIP for Python 3.4 is installed correctly with the following command:

$ pip3.4 -V

As you can see, it works.

Installing Python 3.5 and PIP for Python 3.5

Only Python 3.5:

You can install only Python 3.5 and leave PIP for Python 3.5 with the following command:

$ sudo yum install python35u

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.5 should be installed.

Python 3.5 Including PIP for Python 3.5:

If you want to install Python 3.5 and PIP for Python 3.5, run the following command:

$ sudo yum install python35u python35u-pip

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.5 should be installed along with PIP for Python 3.5.

To test whether Python 3.5 works, run the following command:

$ python3.5 -V

To test whether PIP for Python 3.5 works, run the following command:

$ pip3.5 -V

Installing Python 3.6 and PIP for Python 3.6

Only Python 3.6:

You can install only Python 3.6 and leave PIP for Python 3.6 with the following command:

$ sudo yum install python36u

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.6 should be installed.

Python 3.6 Including PIP for Python 3.6:

If you want to install Python 3.6 and PIP for Python 3.6, run the following command:

$ sudo yum install python36u python36u-pip

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.6 should be installed along with PIP for Python 3.6.

To test whether Python 3.6 works, run the following command:

$ python3.6 -V

To test whether PIP for Python 3.6 works, run the following command:

$ pip3.6 -V

Changing Python Version on the Fly

You can access Python 3 using python3 command.

The default version of Python 3.x used for python3 command is Python 3.4.x.

If you have multiple version of Python 3 installed, you can change it as follows:

$ alias python3=$(which python3.x

NOTE: Here x = 4, 5, or 6 for Python 3.4, Python 3.5, and Python 3.6 respectively.

Now python3 is set to use Python 3.6.x as you can see from the screenshot below.

$ python3 -V

That’s how you install Python 3 on CentOS 7. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Hướng dẫn cài đặt SSH key pair trên ubuntu 20.04 server

SSH hay còn được biết đến là secure shell. Là một phương thức được sử dụng để mã hóa dữ...
30/12/2020

Hướng dẫn reset password bằng Single mode trên Linux (#2)

Ở bài viết trước, Onet đã hướng dẫn các bạn cách reset password trên CentOS bằng Single mode. Trong...
30/12/2020

Jitsi [Part 5] – Hướng dẫn tích hợp Jitsi LDAP

Mặc định, Jitsi cho phép bất cứ ai cũng có thể sử dụng. Vậy nếu bạn là một tổ chức, một...
30/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Dịch Vụ Xây Dựng Hệ Thống Peering Với Internet Exchange (IXP)
04/04/2025

Dịch Vụ Triển Khai VPN Site-to-Site & Remote Access
04/04/2025

Dịch Vụ Thiết Lập Hệ Thống Tường Lửa (Firewall)
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ảo Hóa & Cloud
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ceph
04/04/2025