HA Core won't start after new Python 3.10.9 VENV, throws a bunch of invalid decimal literal errors

Running Core 2022.12.6 in a VENV on RPI4, currently running Python 3.9.8 without any issues. Since Python 3.9 will get deprecated, I downloaded and “altinstalled” Python 3.10.9 just like I did with the past 3-4 Python versions.
But when I try to start HA in the new Python 3.10 VENV, it’s not starting and i’m getting a bunch of errors like these:

2022-12-17 20:34:45.663 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/homeassistant/components/http/forwarded.py", line 82, in forwarded_middleware
    from hass_nabucasa import (  # pylint: disable=import-outside-toplevel
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/hass_nabucasa/__init__.py", line 13, in <module>
    from jose import jwt
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/jwt.py", line 13, in <module>
    from jose import jws
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/jws.py", line 11, in <module>
    from jose import jwk
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/jwk.py", line 8, in <module>
    from jose.utils import base64url_decode, base64url_encode
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/utils.py", line 16, in <module>
    from Crypto.Util.number import long_to_bytes
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/Crypto/Util/number.py", line 139
    value |= 2L ** (N-1)                # Ensure high bit is set
             ^
SyntaxError: invalid decimal literal
2022-12-17 20:34:48.690 ERROR (MainThread) [homeassistant.loader] Unexpected exception importing component homeassistant.components.mobile_app
Traceback (most recent call last):
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/homeassistant/loader.py", line 709, in get_component
    cache[self.domain] = importlib.import_module(self.pkg_path)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/homeassistant/components/mobile_app/__init__.py", line 5, in <module>
    from homeassistant.components import cloud, notify as hass_notify
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/homeassistant/components/cloud/__init__.py", line 9, in <module>
    from hass_nabucasa import Cloud
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/hass_nabucasa/__init__.py", line 13, in <module>
    from jose import jwt
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/jwt.py", line 13, in <module>
    from jose import jws
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/jws.py", line 11, in <module>
    from jose import jwk
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/jwk.py", line 8, in <module>
    from jose.utils import base64url_decode, base64url_encode
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/jose/utils.py", line 16, in <module>
    from Crypto.Util.number import long_to_bytes
  File "/srv/homeassistant_py310/lib/python3.10/site-packages/Crypto/Util/number.py", line 139
    value |= 2L ** (N-1)                # Ensure high bit is set
             ^
SyntaxError: invalid decimal literal

All the packages requirements were installed with a pip3 freeze from my Python 3.9 VENV and no one complained…

Any idea what could be wrong?

Finished updating my VENV on my main system yesterday, having no issues so far. But I did a fresh install with 2022.12.6 into a new VENV with Python 3.10.9, didn’t use pip3 freeze. HA pulled all the missing dependencies during first startup, took quite a while ( about 45 minutes on my PI4 with 4GB).

Only issue was with lirc ( have an IR receiver in my case and use an old TV-Remote to switch on lights), had to compile lirc from source ( pulled from github)

Armin

Thanks for that input, wasn’t sure how HA would react with missing dependencies upon startup, if it does in fact pull them at startup, I guess that’s gonna be my next try!

Hi Andre, you might have a look at this: [solved + howto install python 3.10] Python 3.10 on HA Core: stuck on libpython - #7 by Nick4

Armin suggestion fixed it. Created a new VENV and only installed HA and couple packages I knew I needed and it’s now up and running on Python 3.10 after fetching the missing packages at startup!

Thx!