How to install Python 3.13.0 from source

Published October 11, 2024

Installing Python 3.13.0 from source Installing Python 3.13.0 from source

Python 3.13 was released on October 7, 2024. The latest stable version of Python 3.13 is 3.13.0. It has several new features and optimizations compared to Python 3.12.

Here are steps to install Python 3.13.0 from source on your Linux machine. This tutorial will work for Debian, Ubuntu and their derivatives, Red Hat, Fedora and most Linux operating systems.

New features of Python 3.13

There are a lot of new features in Python 3.13 compared to 3.12. These features include an improved and updated interpreter with multi-line editing and color support and colorized exception tracebacks, a build mode that allows threads to run more concurrently, experimental JIT to improve performance, updated docstrings leading to reduced memory size and size of .pyc files and more. Also, iOS and Android are now Tier 3 supported platforms.

There are also type defaults (PEP 696), a new type narrowing annotation (PEP 742), new annotations for read-only items in TypeDicts and more.

There are also removals of "dead batteries" from the standard battery (PEP 594), many deprecated classes, functions and methods and several more.

Download Python 3.13.0 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.13.0/Python-3.13.0.tgz
tar -xzvf Python-3.13.0.tgz
cd Python-3.13.0/

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 of Python 3.13.0

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.13. To test the version, run this:

python3.13 -V

You will get this output:

Python 3.13.0

Make Python Python 3.13.0 the default version instead of 3.12

To replace the existing version of Python (3.9, 3.10, 3.11 or 3.12) with Python 3.13.0 and make 3.13.0 the default version of Python, first delete the existing softlink to 3.12.

$ sudo rm /usr/local/bin/python

Now, create a new softlink from Python 3.12 to /usr/local/bin/python

$ sudo ln -s /usr/local/bin/python3.13 /usr/local/bin/python

Test whether Python 3.13.0 is the default version:

$ ls -al /usr/local/bin/python
lrwxrwxrwx 1 root root 25 Oct 11 19:31 /usr/local/bin/python -> /usr/local/bin/python3.13
python -VV

The output will be:

Python 3.13.0 (main, Oct 11 2024, 19:24:09) [GCC 10.2.1 20210110]

So, at this point, Python 3.13.0 has been set as the default version of Python.

You can either leave Python 3.12 or older versions of Python pointed to in /usr/local/bin/python* as they are, or uninstall them.

Conclusion

Congratulations! Python 3.13.0 has been installed from scratch on your Linux machine.

If you liked this post, please feel free to share it. If you have any problems installing Python 3.13.0 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.

Disclaimer: Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website.

Last Updated: October 11, 2024.     This post was originally written on October 11, 2024.