Python 3.13 on Fedora 41

This container image is based on Fedora 41 base image. Python’s annual release cycle was adapted for Fedora and Python stack in Fedora 41 upgraded to Python 3.13. By using Fedora’s packages against Python 3.13 while it’s still in development, we can catch critical bugs before the final 3.13.0 release.

Image location: https://hub.docker.com/r/hananmyid/py313

Pull command:

docker pull hananmyid/py313

Docker commands:

FROM quay.io/fedora/fedora-minimal:41

RUN dnf install -y python3 python3-pip; dnf clean all

RUN mkdir /app
WORKDIR /app

ENTRYPOINT ["/usr/bin/python3"]

Create a container instance: docker create --name py313 -it hananmyid/py313 and start it: docker start -ai py313.

You may install Python modules with command: docker exec py313 pip install --no-cache requests. Another way to install Python modules is leveraging the Fedora packages, for example: docker exec py313 dnf -y install python3-requests.

Install the development tools

You may need the development tools to compile from the source:

docker exec py313 dnf -y group install development-tools
docker exec py313 dnf -y install python3-devel

Experimental free-threading build

One of biggest changes in this new version of Python interpreter is experimental support for running in a free-threaded mode (PEP-703). The python3.13-freethreading package in Fedora 41 is build of Python that is built with the --disable-gil option.

The freethreading image tag’s Docker commands:

FROM quay.io/fedora/fedora-minimal:41

ENV VIRTUAL_ENV=/opt/py313t
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN dnf install -y python3.13-freethreading; dnf clean all

RUN mkdir /app
WORKDIR /app

RUN /usr/bin/python3.13t -m venv $VIRTUAL_ENV

ENTRYPOINT ["/opt/py313t/bin/python"]

You may create a container instance same as the default Python image, for example: docker create --name py313-t -it hananmyid/py313:freethreading

For testing purpose, bellow the simple CPU-bound code program multi_threaded.py that performs a countdown using two threads in parallel:

import time
from threading import Thread

COUNT = 100000000

def countdown(n):
    while n>0:
        n -= 1

t1 = Thread(target=countdown, args=(COUNT//2,))
t2 = Thread(target=countdown, args=(COUNT//2,))

start = time.time()
t1.start()
t2.start()
t1.join()
t2.join()
end = time.time()

print('Time taken in seconds -', end - start)

Execute the code: docker exec py313-t python multi_threaded.py

Changelog

  • 2024-12-01: update distro packages
  • 2024-10-29: Fedora 41 released
  • 2024-10-10: update Python 3.13.0
  • 2024-09-27: update the freethreading image
  • 2024-09-23: update distro packages
  • 2024-09-13: add an image tag freethreading for no-GIL option (free threaded CPython)
  • 2024-09-10: update Python 3.13.0rc2
  • 2024-08-16: update distro packages
  • 2024-08-03: update Python 3.13.0rc1

Leave a comment

Leave a Reply