Python 3.13 backport for Debian 12 bookworm

Back again with another backport of Python for the hardcore core users on Debian! This time it is the Python 3.13 backport for Debian 12 bookworm. Python 3.13 is required for Home Assistant 2025.2 which just dropped an hour ago. If you are not familiar with my backports: this is the fourth one in the series: Python 3.8 for Debian 10, Python 3.10 for Debian 11, Python3.12 for Debian 12 and now also Python 3.13 for Debian 12.

Home Assistant is moving faster though Python versions these days, so Debian 12 was the lucky one to have 2 Python backports already (so far)! However I am still of my beliefs that I prefer the core install without Docker, Supervisor or OS. So we keep going with this project!

There are of course other ways to install Python 3.12 such as pyenv or compiling from scratch. Packages are much better manageable than compiling the source from scratch. In my opinion it is also more manageable than using pyenv. By using my packages you will also be sure to get the latest patches (on a best effort basis).

All the info below is a copy-paste of the previous guide, so let me know if there are any errors.

Scope

The scope of this project is limited to backporting just Python 3.13 itself. So no defaults (which provide virtual packages so python3 get’s automatically linked to python3.13) and no precompiled pip-packages or wheels besides pip itself. Therefore it can coexist with your regular Python (3.11) installation without any interference and still being simple to maintain. It’s main use is for in virtual environments where you can use pip to compile and install any packages you desire. It does provide all the packages and dependencies needed to create a Python 3.13 virtual environment.

So if you want something to use Python 3.13, just execute the command as python3.13 instead of python3 or python.

Usage for Home Assistant Core

The usage of my packages is tested for people who followed the Install Home Assistant Core advanced guide.

You can follow the steps below to add my repository to your system and then follow that guide while replacing every instance of python3 with python3.13 to get a working virtual environment. There is one major exception:

  • There is no python3.13-pip package. Pip is included inside the venv-package (in contrary to normally in Debian).

So if you already used that guide before, you only have to install python3.13, python3.13-dev and python3.13-venv:

sudo apt install python3.13 python3.13-venv python3.13-dev

Existing users of a Home Assistant virtual environment created with a different Python version must recreate the environment. This can take a very long time, especially if there are no wheels available for your architecture (armhf is known for this). Upgrading an existing environment is difficult/impossible. It is however possible to create an environment while Home Assistant is running in a different directory, stop Home Assistant and swap them out to minimize downtime.

Repository

NOTE: You should never install keys and add repositories from developers you don’t trust. Decide for yourself if I’m trustworthy and if you have any doubts, check out the source and compile the packages yourself.

Packages can be downloaded from my repository at deb.pascalroeleven.nl. First you should also add my PGP (which you can get from my website via https) to APT’s sources keyring:

wget -qO- https://pascalroeleven.nl/deb-pascalroeleven.gpg | sudo tee /etc/apt/keyrings/deb-pascalroeleven.gpg

Now you can add my repository by adding a file with my repository to the sources.list.d directory:

cat <<EOF | sudo tee /etc/apt/sources.list.d/pascalroeleven.sources
Types: deb
URIs: http://deb.pascalroeleven.nl/python3.13
Suites: bookworm-backports
Components: main
Signed-By: /etc/apt/keyrings/deb-pascalroeleven.gpg
EOF

After running apt update you should now be able to install Python 3.13 related packages.

Chain of trust (sort of)

Packages are built using Github actions along with a file containing the checksums of all packages. Therefore, you can compare the checksums of the packages in the repository with the checksums in Github Actions and trace the entire process (up to 90 days after the build after which the artifacts and logs get removed). This way, if you trust the Github Actions build system, you can be sure that the packages I provide are actually built using the instructions in this repo.

Support

Currently there is support for amd64, arm64 and armhf architectures. The amd64 packages are build natively while the arm64 and armhf packages are crossbuilt. Testing is not possible while crossbuilding, so these packages did not undergo the same amount of testing as usual Debian packages do.

Extra note for people running on armhf (armv7)

As there aren’t a lot of pip wheels available for this architecture, it can be a pain to install Home Assistant Core this way. It requires a lot of extra dependencies such as rustc, ninja-build, cmake and libopenblas0 from what I can remember. Also it can therefore take ages to build this. As I will be using this on armv7 myself, I might provide a tutorial on how to install HASS Core on this architecture in the future.

Questions

For more technical details, you can checkout Github

If something is unclear or if you have any problems, please let me know! I consider myself a somewhat advanced system administrator and I might have skipped over some non-trivial steps somehow.

13 Likes

You’re a saint, dude! My NanoPi Zero 2 only has official images for Debian Bookworm (and some pretty old Ubuntu etc), so I can’t upgrade Debian itself. But thanks to your backports I don’t have to in order to run the latest version of Home-Assistant :slight_smile:

I’ll be updating in a couple of weeks, when I’m on holiday.

1 Like

@pascallj
First, thanks a lot for your work. This never ending chase for the latest Python version can become quite annoying without your initiative!

Trying to upgrade my Hass on Debian amd64 I am getting few conflicts:

risa@hass-mx:~$ sudo apt install python3.13 python3.13-venv python3.13-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-image-6.1.0-26-amd64 linux-image-6.1.0-27-amd64
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libpython3.13 libpython3.13-dev libpython3.13-minimal libpython3.13-stdlib python3.13-minimal
Suggested packages:
  python3.13-doc binfmt-support
The following NEW packages will be installed:
  libpython3.13 libpython3.13-dev libpython3.13-minimal libpython3.13-stdlib python3.13 python3.13-dev
  python3.13-minimal python3.13-venv
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.3 MB of archives.
After this operation, 64.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 libpython3.13-minimal amd64 3.13.2-1~bpo12+1 [859 kB]
Get:2 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 python3.13-minimal amd64 3.13.2-1~bpo12+1 [2,210 kB]
Get:3 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 libpython3.13-stdlib amd64 3.13.2-1~bpo12+1 [1,972 kB]
Get:4 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 libpython3.13 amd64 3.13.2-1~bpo12+1 [2,097 kB]
Get:5 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 libpython3.13-dev amd64 3.13.2-1~bpo12+1 [4,960 kB]
Get:6 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 python3.13 amd64 3.13.2-1~bpo12+1 [1,904 kB]
Get:7 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 python3.13-dev amd64 3.13.2-1~bpo12+1 [506 kB]
Get:8 http://deb.pascalroeleven.nl/python3.13 bookworm-backports/main amd64 python3.13-venv amd64 3.13.2-1~bpo12+1 [1,786 kB]
Fetched 16.3 MB in 5s (2,999 kB/s)     
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 29, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Selecting previously unselected package libpython3.13-minimal:amd64.
(Reading database ... 67427 files and directories currently installed.)
Preparing to unpack .../0-libpython3.13-minimal_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking libpython3.13-minimal:amd64 (3.13.2-1~bpo12+1) ...
Selecting previously unselected package python3.13-minimal.
Preparing to unpack .../1-python3.13-minimal_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking python3.13-minimal (3.13.2-1~bpo12+1) ...
Selecting previously unselected package libpython3.13-stdlib:amd64.
Preparing to unpack .../2-libpython3.13-stdlib_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking libpython3.13-stdlib:amd64 (3.13.2-1~bpo12+1) ...
Selecting previously unselected package libpython3.13:amd64.
Preparing to unpack .../3-libpython3.13_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking libpython3.13:amd64 (3.13.2-1~bpo12+1) ...
Selecting previously unselected package libpython3.13-dev:amd64.
Preparing to unpack .../4-libpython3.13-dev_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking libpython3.13-dev:amd64 (3.13.2-1~bpo12+1) ...
Selecting previously unselected package python3.13.
Preparing to unpack .../5-python3.13_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking python3.13 (3.13.2-1~bpo12+1) ...
dpkg: error processing archive /tmp/apt-dpkg-install-7d6lWA/5-python3.13_3.13.2-1~bpo12+1_amd64.deb (--unpack):
 trying to overwrite '/usr/local/bin/pip3', which is also in package python3.12 3.12.8-3~bpo12+1
Selecting previously unselected package python3.13-dev.
Preparing to unpack .../6-python3.13-dev_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking python3.13-dev (3.13.2-1~bpo12+1) ...
Selecting previously unselected package python3.13-venv.
Preparing to unpack .../7-python3.13-venv_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking python3.13-venv (3.13.2-1~bpo12+1) ...
Errors were encountered while processing:
 /tmp/apt-dpkg-install-7d6lWA/5-python3.13_3.13.2-1~bpo12+1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

First is complaining about missing Python import:

Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 29, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

I am not sure this one is related to the Python package or some quirk in my system install though.

The second one is complaining about overwriting pip:

Selecting previously unselected package python3.13.
Preparing to unpack .../5-python3.13_3.13.2-1~bpo12+1_amd64.deb ...
Unpacking python3.13 (3.13.2-1~bpo12+1) ...
dpkg: error processing archive /tmp/apt-dpkg-install-7d6lWA/5-python3.13_3.13.2-1~bpo12+1_amd64.deb (--unpack):
 trying to overwrite '/usr/local/bin/pip3', which is also in package python3.12 3.12.8-3~bpo12+1

Now the conflicting pip has been installed with the previous version of Python from your repo, so I guess they are part of the package. The question is, if they could be installed into some side-by-side location instead, so the different versions 3.12 and 3.13 coexist without any conflicts?

I managed to fix the first issue.
Apparently I made Python 3.12 my default Python but the apt_pkg which gets installed with the system was only available for Python 3.11.

Fixed this by:

cd /usr/lib/python3/dist-packages
sudo ln -s apt_pkg.cpython-311-x86_64-linux-gnu.so apt_pkg.cpython-312-x86_64-linux-gnu.so

as per linux - python-dev installation error: ImportError: No module named apt_pkg - Stack Overflow

not a true solution for the second issue, but you can force installation with
apt --fix-broken install -o DPkg::options::="--force-overwrite"

1 Like

Thank you for reporting this!

This package isn’t meant to be used as the standard system-wide Python package as you have noticed. It should keep the existing Python system mostly untouched so everything else will keep working as it is.

The second error was indeed unintended and is only noticed now because this bug exists in both my Python 3.12 and Python 3.13 backports. It should also have occurred when the system-wide python3-pip was installed, but apparently no one ever encountered this. The builds are now running and an updated version will uploaded to the repository later today.

If you have applied the mentioned workaround, everything should be fine, however you can get errors/warnings when upgrading or removing one of the packages because the files can not be found.

3 Likes

Right. I get it. It is just there is no “official” Python 3.12 (or 3.13) system package and I did not want to wrap everything into a venv. But the fix for this seemed to be trivial and should not disrupt the official system installation in any way.

For what concerns the second issue, I did what @armin-gh suggested above. This is fine for me. I am getting used to using python -m pip notation to invoke pip so should not be impacted by the global pip binary anyway.

If you fix it in the new build, just the better :+1: .

I upgraded to hass 2025.2.4 today. Couldn’t have gone smoother thanks to this ppa :heart:

Of course I had to reinstall my venv, but that’s no big deal - I’m using the Arch Linux .service file, and that installs everything in .venv, so I just moved my old .venv folder to .venv_backup, changed the exec command from /usr/bin/python3.12 to /usr/bin/python3.13, systemctl daemon-reload, systemctl start home-assistant. And after a few minutes it was running, no problems.

1 Like