This is just a short post to document the required commands to build Python 3 on a CentOS 7.
First we need to install the Development tools and some required sources: e.g. bzip, to support compression in python
yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Next we are downloading and compiling Python 3 as shared library. Compiling Python as shared library is afaik quite common and necessary for third-party tools such as mod_wsgi.
wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz tar xf Python-3.4.1.tgz cd Python-3.4.1 ./configure --prefix=/usr/local --enable-shared make make install
Before we can use Python we need to make the library findable:
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf ldconfig
Finally you should be able to launch python:
python3 --version Python 3.4.1
If you want to remove all the packages we required to compile python, including its dependencies, use the parameter “–remove-leaves” which I also described here.
yum groupremove "Development tools" --remove-leaves yum remove zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel --remove-leaves