Installing Free-threaded Binaries in Python 3.13

Time to talk about installing free-threaded binaries in Python 3.13! (Spoiler alert: it’s not that hard.)

To start why would you want to do this? Well, let’s say you have a fancy new computer with multiple cores and you want your Python programs to take advantage of them. That’s where free-threaded binaries come in! They allow your code to run on multiple threads simultaneously, which can lead to faster execution times (and who doesn’t love that?).

So how do we install these magical creatures? Well, first you need to make sure you have the right version of Python. If you’re using a fancy pants operating system like macOS or Linux, chances are good that it already comes with Python 3.13 installed (yay!). But if you’re on Windows and you don’t want to deal with all those ***** command prompts, you can download the official installer from python.org.

Once you have your preferred version of Python up and running, it’s time to get our hands dirty. First, let’s make sure we have pip installed (if you don’t already). Pip is a package manager for Python that makes it easy to download and install new packages from the internet. To check if you have pip installed, open your terminal or command prompt and type:

# This script checks the version of Python and pip installed on the system.

# The first line uses the "python3" command to check the version of Python installed.
python3 --version

# The second line uses the "pip3" command to check the version of pip installed.
pip3 --version

If everything’s working correctly, you should see something like this:


#!/bin/bash
# This is a bash script that checks the version of Python and pip installed on the system.

# The first line is a shebang, which specifies the interpreter to be used to execute the script.

# The following line uses the command "python --version" to check the version of Python installed.
python_version=$(python --version)

# The output of the command is stored in the variable "python_version".

# The following line uses the command "pip --version" to check the version of pip installed.
pip_version=$(pip --version)

# The output of the command is stored in the variable "pip_version".

# The following line prints the output of the previous two commands, displaying the versions of Python and pip installed.
echo "If everything's working correctly, you should see something like this:"
echo "$python_version"
echo "$pip_version"

# The script ends here.

If you don’t see anything like that, it means pip isn’t installed yet. Don’t worry we can fix that! Just follow these steps:

1. Go to the Python website and download the installer for your operating system (https://www.python.org/downloads/)
2. Run the installer and make sure you select “Add Python 3.x to PATH” during installation
3. Open a new terminal or command prompt window and type:

# This script uses the curl command to download the get-pip.py file from the specified URL and pipes it to the python3 command for execution.

curl https://bootstrap.pypa.io/get-pip.py | python3

# The get-pip.py file is a Python script that installs pip, a package management system used to install and manage software packages written in Python.

# The curl command is used to transfer data from or to a server, in this case, it is used to download the get-pip.py file.

# The python3 command is used to execute the get-pip.py file, which will install pip on the system.

# However, this script is not recommended as it does not specify the version of pip to be installed, which can lead to compatibility issues with other software. It is recommended to use the official Python installer to install pip.

This will download the latest version of pip from the internet and install it for you. Once that’s done, let’s move on to actually installing some free-threaded binaries! For this example, we’re going to use a package called “numba”, which is a just-in-time (JIT) compiler for Python code. It can significantly speed up your programs by compiling them into machine code at runtime.

To install numba using pip, open your terminal or command prompt and type:

# This script installs the "numba" package using pip3, a package manager for Python.

# The following line uses the "pip3" command to install the "numba" package.
# The "-install" flag specifies that we want to install a package.
# The "numba" argument specifies the name of the package we want to install.
pip3 install -install numba

That’s it! Once the installation is complete, you should be able to use numba in your Python programs by importing it like this:

# Import the numba library and alias it as "np" for easier use
import numba as np

And that’s all there is to it! Installing free-threaded binaries in Python 3.13 isn’t rocket science, but it can make a big difference when you need your code to run faster on multiple cores. So give it a try who knows what kind of performance gains you might see?

SICORPS