

We already won’t need the Python source code tarball, so let’s delete it. configure -prefix=/opt/python311 -enable-optimizations -with-system-ffi -with-computed-gotos -enable-loadable-sqlite-extensions -enable-shared LDFLAGS=\"-Wl,-rpath /usr/local/lib\" configure -prefix=/opt/python311 -enable-optimizations -with-system-ffi -with-computed-gotos -enable-loadable-sqlite-extensionsī) compile Python source with SHARED libraries – you should know why you want this option otherwise use option a). How to compile Python: with static libraries or shared libraries? If you don’t know which way to go, then use option a).ĭepending on the number of CPU cores, the compilation will take a few minutes.Ī) compile Python source with STATIC libraries – almost in all of your cases, or if you don´t know, use this option. HINT: To get the number of CPU cores in your Linux CentOS box, use these Bash commands: grep "cpu cores" /proc/cpuinfo or nproc. The command make -j "nproc" will ensure the use of all of your CPU cores and will decrease compile time, and the command make altinstall is critical because it preserves the default shipped Python binary /usr/bin/python. For better performance we are going to use a switch -enable-optimizations for enabling PGO (profile guided optimisation) and so yielding an extra speed boost of Python binaries around 3-10%. Of course, you can choose a folder according to your needs. We are going to use the switch -prefix=/opt/python311 to set the root directory for all Python binaries and libraries. Step 3: Compile the Python source code into binaries.Īt the moment, we have everything ready for compiling the actual Python source code. To do that, perform this set of bash commands. We download the source code of the latest Python from the official Python page: and extract Python-3.11.3.tgz to the /tmp directory. Step 2: Download and unpack the Python source code. sudo yum -y install wget yum-utils gcc openssl-devel bzip2-devel libffi-devel To install them, use the yum command again. I chose the minimal amount of packages those are included in CentOS as well.

To install them, use the yum libraries and developer tools to allow you to build and compile software from source code. You also need some necessary libraries and developer tools to allow you to build and compile software from source code.

Let’s update your CentOS with the yum command. It is a good idea to have an up-to-date operating system before you start doing anything else. Step 1: Prepare CentOS for Python compilation. You will need a functional Linux CentOS 7, 8, or 9 machine, access to the root account, and of course an internet connection.Īll of the steps can be completed as a non-root user, but with the help of the sudo command.

Copy and paste this cheatsheet to install the most recent Python 3.11, 3.10, 3.9, 3.8, or 3.7 on Linux, CentOS 7, 8, and 9.
