How to build Python 3.8 on CentOS 7


You can choose any version you want here

Example: Python 3.8.6
https://www.python.org/downloads/release/python-386/
Source code:
https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz

Step 1: install requirements

yum -y update
yum -y groupinstall "Development Tools"
yum -y install openssl-devel bzip2-devel libffi-devel
yum -y install wget

Step 2:
Download source code

cd /usr/local/src/
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz

Result:

[root@s126368 src]# wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
--2020-10-30 10:03:20--  https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
Resolving www.python.org (www.python.org)... 199.232.72.223, 2a04:4e42:52::223
Connecting to www.python.org (www.python.org)|199.232.72.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24377280 (23M) [application/octet-stream]
Saving to: ‘Python-3.8.6.tgz’

100%[======================================>] 24,377,280  10.8MB/s   in 2.2s

2020-10-30 10:03:23 (10.8 MB/s) - ‘Python-3.8.6.tgz’ saved [24377280/24377280]

Step 3:
Extract tgz file

tar xvf Python-3.8.6.tgz

Step 4:
Change directory

cd Python-3.8*/

Step 5:

./configure --enable-optimizations

Result:

...
checking for glibc _FORTIFY_SOURCE/memmove bug... no
checking for gcc ipa-pure-const bug... no
checking for stdatomic.h... no
checking for GCC >= 4.7 __atomic builtins... yes
checking for ensurepip... upgrade
checking if the dirent structure of a d_type field... yes
checking for the Linux getrandom() syscall... yes
checking for the getrandom() function... no
checking for library containing shm_open... -lrt
checking for sys/mman.h... (cached) yes
checking for shm_open... yes
checking for shm_unlink... yes
checking for pkg-config... /usr/bin/pkg-config
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... yes
checking for --with-ssl-default-suites... python
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup.local
creating Makefile

Step 6:

make altinstall

Result:

...
running install_scripts
copying build/scripts-3.8/pydoc3.8 -> /usr/local/bin
copying build/scripts-3.8/2to3-3.8 -> /usr/local/bin
copying build/scripts-3.8/idle3.8 -> /usr/local/bin
changing mode of /usr/local/bin/pydoc3.8 to 755
changing mode of /usr/local/bin/2to3-3.8 to 755
changing mode of /usr/local/bin/idle3.8 to 755
rm /usr/local/lib/python3.8/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py
rm -r /usr/local/lib/python3.8/lib-dynload/__pycache__
/usr/bin/install -c -m 644 ./Misc/python.man \
        /usr/local/share/man/man1/python3.8.1
if test "xupgrade" != "xno"  ; then \
        case upgrade in \
                upgrade) ensurepip="--altinstall --upgrade" ;; \
                install|*) ensurepip="--altinstall" ;; \
        esac; \
         ./python -E -m ensurepip \
                $ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpjsfxpm1x
Processing /tmp/tmpjsfxpm1x/setuptools-49.2.1-py3-none-any.whl
Processing /tmp/tmpjsfxpm1x/pip-20.2.1-py2.py3-none-any.whl
Installing collected packages: setuptools, pip
Successfully installed pip-20.2.1 setuptools-49.2.1

Done! check:

[root@tutorialspots Python-3.8.6]# python3.8 --version
Python 3.8.6
[root@tutorialspots Python-3.8.6]# pip3.8 --version
pip 20.2.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

Leave a Reply