Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Assistant - Python 3.13 #7293

Open
whyisthisbroken opened this issue Nov 28, 2024 · 22 comments
Open

Home Assistant - Python 3.13 #7293

whyisthisbroken opened this issue Nov 28, 2024 · 22 comments
Milestone

Comments

@whyisthisbroken
Copy link

In the next release of HA with Version 2024.12, Python is raised to version 3.13.

https://rc.home-assistant.io/blog/2024/11/26/release-202412#weve-upgraded-to-python-313

It might lead to certain problems and wanted to let you know in advance.

@yuukiAme
Copy link

yuukiAme commented Dec 2, 2024

No wonder my fresh install of Home Assistant kept being stuck at this stage

Downloading Python-3.12.7.tar.gz...
-> https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz
Installing Python-3.12.7...

@Joulinar
Copy link
Collaborator

Joulinar commented Dec 2, 2024

I doubt that there is a connection. It is to be expected that it will take a while at this stage. Depending on the SBC, it can even take a very long time.

@MichaIng
Copy link
Owner

MichaIng commented Dec 2, 2024

Thanks for the heads up!

But it will still support Python 3.12: https://github.com/home-assistant/core/blob/dev/pyproject.toml

The news is only for the HA containers and appliances. It means at least that most relevant integrations do support Python 3.13 now. We will then also switch, once it is has been released. But no urgency.

@Dynamic5912
Copy link

Got this today after upgrading HA

image

@lukaszsobala
Copy link
Contributor

lukaszsobala commented Dec 5, 2024

@MichaIng I think it's more of an urgent issue...

I was having this error after updating to hass 2024.12: home-assistant/core#131997
Tried a few things in pyenv like updating av but nothing worked. Only upgrading to python 3.13 helped. I did this by modifying the python version in dietpi-software to 3.13.0 and issuing dietpi-software reinstall 157. Now there are no errors.

To be fair, I did not try reinstalling without this mod, so maybe 3.12.7 would still work...

@Dynamic5912
Copy link

Mine is working but I got the "warning" message I posted above.

They're not deprecating old Python until Feb 2025 for HA Core

@MichaIng
Copy link
Owner

MichaIng commented Dec 5, 2024

@lukaszsobala
The issue you linked is an error with the new HA version and Python 3.13, while someone solved it while still using Python 3.12. I guess the reinstall solved it for you, since it reinstalls all dependencies from scratch, including possibly needed updates.

To be fair, I did not try reinstalling without this mod, so maybe 3.12.7 would still work...

I guess so. But I'll keep it in mind, in case someone else reports it.

Ah, and, since 2024.12 is released now, I'll update ours to Python 3.13 now anyway.

MichaIng added a commit that referenced this issue Dec 5, 2024
- DietPi-Software | Home Assistant: Raise Python version to 3.13, as Python 3.12 support is deprecated by HA since 2024.12 and will be removed with 2025.02: #7293
@MichaIng
Copy link
Owner

MichaIng commented Dec 5, 2024

Done: de0af4b

@MichaIng MichaIng added the Solution available 🥂 Definite solution has been done label Dec 5, 2024
@MichaIng MichaIng modified the milestones: v9.10, v9.9 Dec 5, 2024
@vdvdnk
Copy link

vdvdnk commented Dec 10, 2024

I'm using fresh install of DietPi + HA with Python version 3.13.1 and got next error:

Unable to install package av==13.1.0
src/av/codec/context.c:15851:48: error: ‘AV_CODEC_FLAG_FRAME_DURATION’ undeclared (first use in this function); and many others related to AV_CODEC_FLAG_

@MichaIng
Copy link
Owner

MichaIng commented Dec 10, 2024

@vdvdnk
But HA starts up and is usable, right? Since we do not install FFmpeg with HA OOTB, logically all Python modules which try to load it fail, respectively run into errors. However, HA core does not require FFmpeg, but only video/audio/camera integrations do. Don't ask me why HA core adds heavy Python modules as dependencies which are needed only for a minority of users. I complained about this since years, but it keeps growing like this.

@vdvdnk
Copy link

vdvdnk commented Dec 10, 2024

@MichaIng
Yes it starts up and usable

@MichaIng
Copy link
Owner

If anything does not work, like mentioned audio/video/camera integrations which require decoding or encoding on the HA host system, then:

apt install ffmpeg

That should also mute the error. But the set of libraries is huge, which is why we do not install it OOTB.

@vdvdnk
Copy link

vdvdnk commented Dec 10, 2024

Note that I also installed ffmpeg and libavcodec, error still persist. In previous version of HA 2024.11 no such errors (at least I haven't noticed that)

@MichaIng
Copy link
Owner

Ah hmm, then it is probably an issue with the FFmpeg version. ... indeed AV_CODEC_FLAG_FRAME_DURATION is declared in FFmpeg 6 but not in FFmpeg 5. But Debian Bookworm ships FFmpeg 5 only:

The av module uses it since v13.1:

Not sure whether they were aware it is a breaking change, but IIRC FFmpeg 6 was actually declared as dependency already.

Home Assistant declares v13.1 as minimum dependency version:

In v2023.11 it was still their own fork ha-av, which obviously did not contain this change yet:

Newer FFmpeg is available through this repository:

@vdvdnk
Copy link

vdvdnk commented Dec 10, 2024

Thanks for the investigation! With FFmpeg from deb-multimedia.org av compiled successfully and HA works without any issues.

@MichaIng
Copy link
Owner

It is sadly difficult to implement this by default into DietPi FFmpeg installations. It contains a lot of other software and libraries, which can be incompatible with other Debian packages which depend on them, including own media packages we provide for each Debian version. And on RPi, the Kodi build from the RPi repo is needed to provide full hardware acceleration, while the one from the multimedia.org repo has a higher epoch version, hence will forcefully be installed ... and the one from RPi repo is likely not compatible with the shared libs from that repo etc etc 😄.

The switch (back) from ha-av to av was done here: home-assistant/core#129699
A needed feature was added in v12.1.0 already, hence as a workaround, we could change the version dependency to 13.0.0.

@Dynamic5912
Copy link

Some errors for me today:

image

image

Traceback (most recent call last):
File "/home/homeassistant/.pyenv/versions/3.12.1/lib/python3.12/site-packages/homeassistant/setup.py", line 416, in _async_setup_component
result = await task
^^^^^^^^^^
File "/home/homeassistant/.pyenv/versions/3.12.1/lib/python3.12/site-packages/homeassistant/components/stream/init.py", line 226, in async_setup
await hass.async_add_executor_job(set_pyav_logging, debug_enabled)
File "/home/homeassistant/.pyenv/versions/3.12.1/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.pyenv/versions/3.12.1/lib/python3.12/site-packages/homeassistant/components/stream/init.py", line 196, in set_pyav_logging
import av # pylint: disable=import-outside-toplevel
^^^^^^^^^
File "/home/homeassistant/.pyenv/versions/3.12.1/lib/python3.12/site-packages/av/init.py", line 17, in
from av.bitstream import BitStreamFilterContext, bitstream_filters_available
File "/home/homeassistant/.pyenv/versions/3.12.1/lib/python3.12/site-packages/av/bitstream/init.py", line 1, in
from .context import BitStreamFilterContext
File "av/bitstream/context.pyx", line 1, in init av.bitstream.context
ValueError: av.frame.Frame size changed, may indicate binary incompatibility. Expected 56 from C header, got 48 from PyObject

image

@lukaszsobala
Copy link
Contributor

Solution seems to be here home-assistant/core#131997 (comment)

@MichaIng
Copy link
Owner

So it is two dedicated issues: one as of left over files from ha-av when migrating to av, causing @Dynamic5912's error, and is solved by explicitly uninstalling the ha-av module, before the migration, or uninstalling av once to cleanup, then let HA pull is freshly.

The other one is due to av 13.1.0 requiring FFmpeg 6, which is not available on Debian Bookworm natively. It does not crash anything, but video and camera integrations might not work or run into actual GUI/usage failures. In this case, adding https://www.deb-multimedia.org/ is a workaround, of upgrading to Debian Trixie, which ships FFmpeg 7.

I'll test whether manually pinning down the av version to 13.0.0 works.

@Dynamic5912
Copy link

Do I need to do anything or await further instructions/next DietPi release?

@MichaIng
Copy link
Owner

Next DietPi release will ship HA with Python 3. But it most likely won't have the FFmpeg issue worked around yet.

@whyisthisbroken
Copy link
Author

whyisthisbroken commented Dec 21, 2024

So, compiled ffmpeg by myself and install it, removed the old one from the deb rep and do the fix from here home-assistant/core#131997 (comment)

Everything works fine - now waiting for the python 3.13 fix with the next dietpi release and all done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants