Happy Holiday and greeting from Unixzone…
In this lesson, we want to learn how to install python3 on centos 7. By default, in the new release of centos, python 3.6.X is available to install from the default repository. However, there is no chance to install from the default repository for the upper version.
First we will cover install python from default repository :
1 – Update your OS to the latest version of centos 7.
yum update -y
2 – Install development tools and some prerequisite packages.
yum groupinstall -y "Development Tools" && yum install gcc openssl-devel bzip2-devel libffi-devel -y
3 – Install python3 from repository.
yum install python3 -y
4 – Confirm python is installed or not.
[root@website ~]# python3.6 -V
Python 3.6.8
The second method is to install from the source, which is very useful in many environments, especially when you do not have root access and are a normal user and want to have a python for running your project.
1 – Download the desired version of python3 based on your requirements. In this case, the tutorial supports the latest version of 3.6.X.
wget -c https://www.python.org/ftp/python/3.6.14/Python-3.6.14.tar.xz
2 – Install development tools and some prerequisite packages.
yum groupinstall -y "Development Tools" && yum install gcc openssl-devel bzip2-devel libffi-devel -y
3 – extract th file.
tar -xf Python-3.6.14.tar.xz
4 – enter to the directory.
cd Python-3.6.14
5 – edit setup file for enabling SSL.
This step is crucial because SSL must be enabled on python in most cases.
if you are compiling python 3.6.X below file must be edited :
vi Modules/Setup.dist
on new version such as 3.7 or 3.8, name of file is changed to below one :
vi Modules/Setup
find SSL lines and uncommnet below lines:
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
there must not be any # at the first of the above lines. Save and exit it.
6 – configure the python on the desired path.
./configure --prefix=/data/Python3.6.14
7 – make it.
make
8 – finally, make then install on the desired path.
make install
9 – check installed python with below command.
/data/Python3.6.14/bin/python3.6 -V
I hope, enjoy this article. Put your comments for me in order to improve the quality of posts.