You can use official docker Python image. In the tag you can use the python version you need and they have different OS for the same versions of Python. For example

python:3.12.1-bookworm

python:3.12.1-bullseye

python:3.12.1-alpine3.19

Answer from 0x00 on Stack Overflow
🌐
Python.org
discuss.python.org › python help
Python 3.12 build on Raspberry Pi 4 Bullseye - Python Help - Discussions on Python.org
October 7, 2023 - Running Debian GNU/Linux 11 (bullseye), downloaded source and ran ./configure --enable-optimizations which seemed ok. However make -j4 fails towards the end with missing modules: make[1]: Entering directory '/home/pi/Python-3.12.0' The necessary bits to build these optional modules were not ...
Discussions

What is the proper way to install Python 3.10 or higher on Docker development environments - Stack Overflow
I use the docker/dev-environments-default:stable-1 as a base image for development environments. However, the OS version (Debian Bullseye) only supports Python versions up to 3.9 via apt, so I can ... More on stackoverflow.com
🌐 stackoverflow.com
Why does python:latest Docker tag point at the python:3.10.1-bullseye tag?
Docker image security scanners are kind of notoriously inaccurate and especially so with Debian images . More on reddit.com
🌐 r/Python
15
15
January 6, 2022
Installing Python 3.11.1 on a docker container - Stack Overflow
I don't want to use a base Python image - I want to control installation myself on debian:bullseye. 2023-01-18T14:41:12.15Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
Python3.12-bullseye cannot find codec on linux/arm64/v8
Upon running an image using python:3.12-bullseye for aarch64 as base, Python fails with the following error: Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = '/usr/local/bin/python3.12' isolated = 0 environment = 1 user site = 1 safe_path = 0 import site ... More on github.com
🌐 github.com
6
December 19, 2024
🌐
Docker
hub.docker.com › layers › library › python › 3.12.1-bullseye › images › sha256-0a152c9b2f84bb9bedc75cb028b64cf39e9c89be2da8aa2c5f87d35755d62e65
Image Layer Details - python:3.12.1-bullseye
Welcome to the world's largest container registry built for developers and open source contributors to find, use, and share their container images. Build, push and pull.
🌐
GitHub
github.com › docker-library › official-images › blob › master › library › python
official-images/library/python at master · docker-library/official-images
2 weeks ago - # this file is generated via https://github.com/docker-library/python/blob/59e4abf1fb132d2f7be0b808bdc0b3e616519eeb/generate-stackbrew-library.sh ... Tags: 3.14.4-slim-trixie, 3.14-slim-trixie, 3-slim-trixie, slim-trixie, 3.14.4-slim, 3.14-slim, 3-slim, slim
Author   docker-library
🌐
Snyk
snyk.io › test › docker › python:3.12-rc-slim-bullseye
Vulnerability report for Docker python:3.12-rc-slim-bullseye | Snyk
The FIPS modules in 3.6, 3.5, 3.4, 3.3 and 3.0 are not affected by this issue, as the PKCS#12 implementation is outside the OpenSSL FIPS module boundary. OpenSSL 3.6, 3.5, 3.4, 3.3, 3.0, 1.1.1 and 1.0.2 are vulnerable to this issue.
🌐
Debian
packages.debian.org › bullseye › python
Debian -- Software Packages in "bullseye", Subsection python
Biopython support for the BioSQL database schema (Python 3) python3-biosig (2.1.2-4) Python3 bindings for BioSig library · python3-biotools (1.2.12-5) Python3 bioinformatics utilities for high-throughput genomic sequencing · python3-bip32utils (0.0~git20170118.dd9c541-2) Python implementation of Bitcoin hierarchical deterministic wallet ·
🌐
ECR Public Gallery
gallery.ecr.aws › docker › library › python
Amazon ECR Public Gallery - Docker/library/python
[Docker Official Images] Python is an interpreted, interactive, object-oriented, open-source programming language. ... 3.12.0-slim-bookworm, 3.12-slim-bookworm, 3-slim-bookworm, slim-bookworm, 3.12.0-slim, 3.12-slim, 3-slim, slim · 3.12.0-bullseye, 3.12-bullseye, 3-bullseye, bullseye
Find elsewhere
🌐
Docker Hub
hub.docker.com › _ › python
python - Official Image | Docker Hub
Python is an interpreted, interactive, object-oriented, open-source programming language. ... Where to get help: the Docker Community Slack⁠, Server Fault⁠, Unix & Linux⁠, or Stack Overflow⁠ · (See "What's the difference between 'Shared' and 'Simple' tags?" in the FAQ⁠.) ... 3.14.4-slim-trixie, 3.14-slim-trixie, 3-slim-trixie, slim-trixie, 3.14.4-slim, 3.14-slim, 3-slim, slim⁠
🌐
Reddit
reddit.com › r/python › why does python:latest docker tag point at the python:3.10.1-bullseye tag?
r/Python on Reddit: Why does python:latest Docker tag point at the python:3.10.1-bullseye tag?
January 6, 2022 -

Currently, if you docker pull python you'll get a Python 3.10.1 image based on Debian Bullseye.

This is what most people will do by default if they want a Python Docker image.

However, this image has many packages installed (which I'm guessing most people won't require?) with a significant number of vulnerabilities.

There are plenty of other images with the same version of Python that have a significantly smaller footprint:

https://dso.atomist.com/images/python

Most of them are either Alpine based or slim Debian images.

I'm just worried about the tyranny of the default here, and that we might be inadvertently exposing folks to vulnerabilities unnecessarily.

What do people think?

Top answer
1 of 3
9

In case you want to install Python 3.11 in debian bullseye you have to compile it from source following the next steps (inside the Dockerfile):

sudo apt update
sudo apt install software-properties-common wget
wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tar.xz
sudo tar -xf Python-3.11.1.tar.xz
cd Python-3.11.1
sudo ./configure --enable-optimizations
sudo make altinstall

Another option (easiest) would be to use the official Python Docker image, in your case:

FROM 3.11-bullseye

You have all the versions available in docker hub.

Other option that could be interesting in your case is 3.11-slim-bullseye, that is an image that does not contain the common packages contained in the default tag and only contains the minimal packages needed to run python.

2 of 3
6

Based on @tomasborella answer, to do this in docker:

Dockerfile

FROM debian:bullseye

RUN apt-get update -y \
    && apt-get upgrade -y \
    && apt-get -y install build-essential \
        zlib1g-dev \
        libncurses5-dev \
        libgdbm-dev \ 
        libnss3-dev \
        libssl-dev \
        libreadline-dev \
        libffi-dev \
        libsqlite3-dev \
        libbz2-dev \
        wget \
    && export DEBIAN_FRONTEND=noninteractive \
    && apt-get purge -y imagemagick imagemagick-6-common 

RUN cd /usr/src \
    && wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz \
    && tar -xzf Python-3.11.0.tgz \
    && cd Python-3.11.0 \
    && ./configure --enable-optimizations \
    && make altinstall

RUN update-alternatives --install /usr/bin/python python /usr/local/bin/python3.11 1

update-alternatives - will update the links to allow you to run python as opposed to specifying python3.11 when you want to run it.

It takes a while to compile those sources!

🌐
Microsoft
mcr.microsoft.com › en-us › product › devcontainers › python › about
Python Development Container Images
mcr.microsoft.com/devcontainers/python:3.14 (or 3.14-trixie, 3.14-bookworm to pin to an OS version) Refer to this guide for more details.
🌐
Medium
andypickup.com › developing-in-python-with-dev-containers-part-1-setup-f1aeb89cbfed
Developing in Python with Dev Containers — Part 1: Setup | by Andy Pickup | Medium
April 15, 2024 - { "name": "Python 3", "image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye", "remoteUser": "vscode", "customizations": { "vscode": { "settings": {}, "extensions": [ "gruntfuggly.todo-tree", "ms-azuretools.vscode-docker", "samuelcolvin.jinjahtml", "mhutchie.git-graph", "ms-python.python", "ms-python.vscode-pylance", "ryanluker.vscode-coverage-gutters", "meezilla.json", "eamodio.gitlens", "emmanuelbeziat.vscode-great-icons", "dongido.sync-env", "yzhang.markdown-all-in-one", "postman.postman-for-vscode", "github.vscode-github-actions", "foxundermoon.shell-format", "shardulm94.trailing-spaces", "github.vscode-pull-request-github", "github.copilot", "github.copilot-chat" ] } } }
🌐
GitHub
gist.github.com › lemajes › 714734059fc88ff259bf6d94c41bdfb0
PYTHON 3.12 Debian Bullseye 101 · GitHub
PYTHON 3.12 Debian Bullseye 101 · Raw · python3_12_debian_bullseye_101.md · cd /tmp/ wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz tar -xzvf Python-3.12.2.tgz cd Python-3.12.2/ Install the build tools · Now, install the build tools. The build tools includes gcc, make, zlib, ssl libraries and other libraries.
🌐
Medium
medium.com › @anuj.sadani › understanding-python-docker-images-bullseye-bookworm-and-trixie-e68508876a93
Understanding Python Docker Images: Bullseye, Bookworm, and Trixie | by Anuj Sadani | Medium
August 24, 2025 - Example: Perfect for AI research with PyTorch nightly builds requiring CUDA 12.4 and GCC 14, but risky for production until stable. ... Stick with Bookworm for most production apps today → stable + modern enough. Use Bullseye only if you’re tied to older dependencies or need reproducibility in enterprise/legacy systems. Experiment with Trixie if you need the absolute latest toolchains (AI research, HPC), but avoid in production until Debian 13 is officially stable. When choosing a Python Docker image, don’t just pick python:3.11 blindly.
Top answer
1 of 2
1

I'm struggling to get tkinter working with Python 3.13.0 myself on Linux Mint 22.

Tkinter is working fine with Python 3.12.3 (default from the Synaptic package manager).

I followed the instructions at How to install Python 3.13.0 from source.

$ python3.13
    Python 3.13.0 (main, Oct 25 2024, 20:06:35) [GCC 13.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tkinter
    Traceback (most recent call last):
      File "<python-input-0>", line 1, in <module>
        import tkinter
      File "/usr/local/lib/python3.13/tkinter/__init__.py", line 38, in <module>
        import _tkinter # If this fails your Python may not be configured for Tk
        ^^^^^^^^^^^^^^^
    ModuleNotFoundError: No module named '_tkinter'

The main reason I'm doing this is because 3.13.0 has a problem on Windows 3.13.0 tkinter versus venv in windows 10, and I wanted to test it on Linux.

There is a really informative post here: Why does tkinter (or turtle) seem to be missing or broken? Shouldn't it be part of the standard library? by Karl Knechtel, which I thought you might like to see.

Another command I have come across that might help is sudo apt-get install python3.13-tk. This package is not available in the LM repository, but I'll add the Ubuntu PPA and try it later. The LM repository has a python3-tk package, but it has not yet been updated for Python 3.13.0.

There's also a nice video at How to install the latest Python version ( Python3.13 ) on Ubuntu 24.04

No guarantees, I'm just making suggestions at this stage.

2 of 2
0

In the bullseye raspberry pi repository:

Regarding Question 1:

Question 1: Why is there available both tk-dev and tk8.6-dev? Are both v. 8.6?

Both tk-dev and tk8.6-dev are version 8.6. It seems that tk8.6-dev is a later version, unless I'm reading that wrong?

tk-dev/oldstable 8.6.11+1 arm64
  Toolkit for Tcl and X11 (default version) - development files

tk8.6-dev/oldstable 8.6.11-2 arm64
  Tk toolkit for Tcl and X11 v8.6 - development files

More helpful details are documented at

https://tracker.debian.org/pkg/tk8.6

verifying that version 8.6.11-2 is indeed stable, even though not the very latest stable version (which is 8.6.13-2).

And this from

https://www.tcl.tk/software/tcltk/8.6.html

-----------------------

Latest Release: Tcl/Tk 8.6.15 (Sep 13, 2024)

First released in 2012, Tcl/Tk 8.6.* is the current supported series of releases.

-----------------------

So, 8.6.15-1 is latest but undergoing testing and still considered unstable.

Therefore, I will not use the tk-dev, but instead will get the tk8.6-dev and tcl8.6-dev from the default pi bullseye repository, before building any future python 3.12.5 or greater. In case I find it helpful to ask the raspberry pi folks for further support, I am sticking with their repository versions of these libraries rather than getting the absolute latest from www.tcl.tk. I may change my position on this after some testing and further research.


edit - see also comment @acw1668 thank you for steering me to looking into what is an apt meta package.

https://installati.one/install-tk-dev-debian-12

then made it clear that it is tk-dev that I should install with apt, which will take care of all the packages I was actually considering that I might need to install for my particular tkinter projects, including tk8.6-dev.

That link detailed all the packages I was thinking I might, and probably should install. Although it did not go into detail of what each contributes to the final functionality, it was enough to conclude that it is the tk-dev metapackage that will be my dependency solution.


Regarding Question 2:

Question 2: Can you detail anything I might be missing in this plan, or anything that I do not need to install before the make altinstall of python 3.13, for ensuring full tkinter 8.6 support in python 3.13?

Question 3: (ammended)

I intend to access and play audio files using the final tkinter project. Does anyone have helpful remarks on needed libraries, before the python 3.12.x or python 3.13.x build, that might be needed to ensure full robust audio support specifically in a tkinter project? I can submit this as a separate question if you think that more appropriate for clarity.

Thank you for your thoughts on these matters.

🌐
Tonmann
tonmann.com › 2023 › 07 › 02 › update-python-to-3-11-on-raspbian-bullseye
Update Python to 3.11 on Raspbian Bullseye – Tonmann.com
July 2, 2023 - We need the path for the old Python 3.9 that comes with Bullseye, too: ll $(which python3)* lrwxrwxrwx 1 root root 9 5. Apr 2021 /usr/bin/python3 -> python3.9 -rwxr-xr-x 1 root root 4703672 12.