I’ve been getting back into learning and using Python recently. This is a quick post on how to compile and install Python 3.7 on Centos 7. In this case I’ll be using a Centos Docker container.
First we need to install the development tools. This installs the tools we will need in order to compile python from source.
# yum groupinstall -y "Development Tools" # yum install -y zlib-devel
Next we want to switch directory to where we will download the python source code:
# cd /usr/src
Next we want to download the python package using wget:
wget ht tps://python.org/ftp/pthon/3.7.3/Python-3.7.3.tar.xz
OK, with that done we need to unpack the python package:
tar xf Python-3.7.3.tar.xz
Now, switch directory to the newly created ‘Python-3.7.3’ directory. You should see a bunch of files:
[root@ef0c0ef422d7 Python-3.7.3]# ls CODE_OF_CONDUCT.rst Include Mac Modules PCbuild Python aclocal.m4 configure m4 Doc LICENSE Makefile.pre.in Objects Parser README.rst config.guess configure.ac pyconfig.h.in Grammar Lib Misc PC Programs Tools config.sub install-sh setup.py
Now we can compile the package with the following two commands:
./configure --enable-optimizations --with-ensurepip=install make altinstall
Once the process completes we can run Python 3.7 by running:
[root@ef0c0ef422d7 Python-3.7.3]# python3.7 Python 3.7.3 (default, Jan 15 2020, 15:07:41) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
Now you’re ready to do some Python coding!!