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
Answer from 0x00 on Stack Overflowpython:3.12.1-bookworm
python:3.12.1-bullseye
python:3.12.1-alpine3.19
What is the proper way to install Python 3.10 or higher on Docker development environments - Stack Overflow
Why does python:latest Docker tag point at the python:3.10.1-bullseye tag?
Installing Python 3.11.1 on a docker container - Stack Overflow
Python3.12-bullseye cannot find codec on linux/arm64/v8
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?
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.
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!
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.
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.