Installing Python 3.12.7 from source
The latest version of Python 3.12 is 3.12.7 and is the seventh maintenance release, with more than 120 bug fixes, build improvements and documentation changes since 3.12.6.
Here are steps to install Python 3.12.7 from source on your Linux machine. This tutorial will work for Debian, Ubuntu and their derivatives, Red Hat, Fedora and most Linux operating systems.
Download Python 3.12.7 source
The latest Python source code is available here.
First, download and extract the latest Python source code.
cd /tmp/ wget https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz tar -xzvf Python-3.12.7.tgz cd Python-3.12.7/
Install the build tools
Now, install the build tools. The build tools includes gcc, make, zlib, ssl libraries and other libraries.
On Debian or Ubuntu:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev
On Red Hat or Fedora:
sudo dnf update sudo dnf groupinstall "Development Tools" "Development Libraries"
Configure, make and make install
./configure --enable-optimizations
Before running make
, find the number of processors your server has using nproc
.
nproc
You will see something like this:
6
Now, run make with the number of processors. This may take a while.
make -j 6
You can also run make
and use the nproc
or $(nproc)
output in one step:
make -j $(nproc)
Why does the make command take so long to complete?
The make -j
command can be faster when there more than a single processor because it uses all the available CPUs, so the build is done in parallel with each CPU contributing to it.
The slowest is when your computer has a single processor. In that case, these two are equivalent and have the slowest build time.
make
make -j 1
How to speed up the make command execution time
If you are building Python from scratch in a VM (virtual machine), before you start, increase the number of cores to 4 or more. Then start your VM and follow the steps. By doing this, the make command will take much lesser time.
Make install
We will install Python under /usr/local/bin
instead of overwriting the default Python installation under /usr/bin
.
sudo make altinstall
This will install Python at /usr/local/bin/python3.12
. To test the version, run this:
python3.12 -V
You will get this output:
Python 3.12.7
Make Python 3.12.7 the default version
To make the default version of Python 3.12.7, run this:
$ sudo ln -s /usr/local/bin/python3.12 /usr/local/bin/python
Test whether Python 3.12.7 is the default version:
$ ls -al /usr/local/bin/python
lrwxrwxrwx 1 root root 25 Dec 26 2023 /usr/local/bin/python -> /usr/local/bin/python3.12
python -VV
The output will be:
Python 3.12.7 (main, Oct 11 2024, 19:00:23) [GCC 10.2.1 20210110]
So, at this point, Python 3.12.7 has been set as the default version of Python.
If you liked this post, please feel free to share it. If you have any problems installing Python 3.12.7 from source, you may contact me.
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.