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

Cách sử dụng Fail2ban để bảo mật máy chủ CentOS

Mục lục Giới thiệu Cài đặt và cấu hình Giám sát cấu hình firewall và nhật ký Fail2ban Giám...
30/12/2020

NextCloud – Giải pháp lưu trữ đám mây cho doanh nghiệp.

Nextcloud cung cấp đến doanh nghiệp của bạn nền tảng lưu trữ đám mây, lưu trữ một nơi xem,...
30/12/2020

[DNS] Cấu hình DNS Server trên CentOS 8

Hiện nay với sự ra đời của mọi thiết bị kết nối Internet (Internet of Things), số lượng địa...
30/12/2020
Bài Viết

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

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024