Building Python 3.5 for CentOS

Update: As per Alexander Todorov’s suggestion using https://www.softwarecollections.org/ is much easier and saves a lot of trouble compiling.

So after git it’s time to upgrade python. CentOS 7 has python 3.4, but there are some small but very annoying incompatibilities with 3.5. And it seems that 3.5 will be the major python 3 release. So here we go:

RPM build chroot

First lets create the chroot directory and  initialize the  rpm database   :

Next  install the latest centos-release package,  yum and add the EPEL inside the chroot:

Next we continue inside the chroot :

Building RPMs

Next we need to install gcc, and few other packages that are needed to compile RPMs and pyton.

Pick a python 3.5 SRPM from https://apps.fedoraproject.org/packages/python3 .

And install it :

You can just ignore the warning about missing users. Go to SPECS directory and edit python3.spec so that :

becomes

This has something to do with a circular dependency of the rewheel package. Now we can build python with:

After the build is done we can check if the packages are installable:

Now let’s try to rebuild with the rewheel package. We will need python-rpm-macros, python3-pip and python3-setuptools  and a bunch of other packages for building them 🙂

Change back python3.spec to:

And now rebuild python3 again:

After the build finishes we have the RPMs in ~/rpmbuild/RPMS:

Exit the chroot and install the newly build python 3.5 packages :

2 thoughts on “Building Python 3.5 for CentOS”

  1. Just FYI I’m using Python 3.5 on RHEL 7 via the Software Collections which should work/be available for CentOS as well. It should save you the trouble of compiling everything from scratch.

    1. 😀 Next time I am directly asking you what is the easier way ..
      Never heard of this Software collections befoire.

Leave a comment