I found a guide how to build (compile) the most recent Python-versions on the Pi here.
This guide still works on “Bullseye” and also with Python 3.11. However, I’d recommend to miss out the part with deletion of the symlink at /usr/bin though, but use the “update-alternatives”-tool instead.
One just need some patience as the compile takes nearly an hour. After that, the new binaries can be found at /usr/local/bin:
-rwxr-xr-x 1 root root 23915388 2. Jul 13:26 /usr/local/bin/python3.11
-rwxr-xr-x 1 root root 3053 2. Jul 14:43 /usr/local/bin/python3.11-config
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. Mär 2021 /usr/bin/python3.9
Now we can add entries to “alternatives” for “python3”:
sudo update-alternatives --install /usr/local/bin/python3 python3 /usr/local/bin/python3.11 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
The next step is to make Python 3.11 the default for “python3”:
sudo update-alternatives --config python3 -> Select the number representing the compiled Python 3.11 to make it the new default.