Installing Home Assistant Core 2023.5.4 in a Python 3.11 vEnv on Raspberry Pi 3B+ step by step

I have perfectly working instalation of Home Assistant Core 2023.3.2 in venv running by python 3.10.
Because I read in changelog that now is python 3.11 suported i tryed to install Assistant Core 2023.5.4 in venv with python 3.11.

I installed Home Assistant Core 2023.5.4 in a virtual environment (pip) on a clean Raspberry Pi 3B+ device(debian 11).

I tired following this official guide: Install Home Assistant Core

Prerequisites

This guide assumes that you already have an operating system setup and have installed Python 3.11 (including the package python3-dev) or newer.

I’ve updated to Python 3.11 and installed 2023.5.4

Quick start

step 1. Install latest Python 3.11.3 version on Raspberry Pi
You can allways build python from source, and that is not to complicated

Create and change to a virtual environment for Home Assistant Core

sudo useradd -rm homeassistant -G dialout,gpio,i2c


#create a directory for the installation of Home Assistant Core
sudo mkdir /srv/homeassistant

#change the owner to the homeassistant account
sudo chown homeassistant:homeassistant /srv/homeassistant

sudo -u homeassistant -H -s
cd /srv/homeassistant
python3.11 -m venv .
source bin/activate

before install Home Assistant Core( in a Python 3.11 virtual environment)

pip install --upgrade pip
python3 -m pip install wheel

Install Home Assistant Core


#Stop the Homeassistant service for free port 8123 (not  in a Python 3.11 vEnv)
sudo systemctl stop home-assistant@homeassistant
# (in a virtual environment)
pip3 install homeassistant==2023.5.4  

resolve some errors (in a virtual environment)

curl https://sh.rustup.rs -sSf | sh  
pip3 install cryptography
pip3 install pyOpenSSL --upgrade

second install ok

#Stop the Homeassistant service for free port 8123 (not in a Python 3.11 vEnv)

sudo systemctl stop home-assistant@homeassistant
sudo -u homeassistant -H -s
cd /srv/homeassistant
source bin/activate

pip3 install homeassistant==2023.5.4  

output

(homeassistant) homeassistant@raspberrypi:/srv/homeassistant $ pip3 install homeassistant==2023.5.4
Looking in indexes: https://mirrors.aliyun.com/pypi/simple, https://www.piwheels.org/simple
Collecting homeassistant==2023.5.4
  Downloading https://mirrors.aliyun.com/pypi/packages/cd/c3/db1a46937290d480c30ed8ee7c71926973c590f1afa8bd0fb7222b998ce2/homeassistant-2023.5.4-py3-none-any.whl (24.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 24.9/24.9 MB 68.0 kB/s eta 0:00:00
Collecting aiohttp==3.8.4 (from homeassistant==2023.5.4)
  Using cached aiohttp-3.8.4-cp311-cp311-linux_armv7l.whl
Collecting astral==2.2 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/astral/astral-2.2-py2.py3-none-any.whl (30 kB)
Collecting async-timeout==4.0.2 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/async-timeout/async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting attrs==22.2.0 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/attrs/attrs-22.2.0-py3-none-any.whl (60 kB)
Collecting atomicwrites-homeassistant==1.4.1 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/atomicwrites-homeassistant/atomicwrites_homeassistant-1.4.1-py2.py3-none-any.whl (7.1 kB)
Collecting awesomeversion==22.9.0 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/awesomeversion/awesomeversion-22.9.0-py3-none-any.whl (12 kB)
Collecting bcrypt==4.0.1 (from homeassistant==2023.5.4)
  Using cached bcrypt-4.0.1-cp311-cp311-linux_armv7l.whl
Collecting certifi>=2021.5.30 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/certifi/certifi-2023.5.7-py3-none-any.whl (156 kB)
Collecting ciso8601==2.3.0 (from homeassistant==2023.5.4)
  Using cached ciso8601-2.3.0-cp311-cp311-linux_armv7l.whl
Collecting httpx==0.24.1 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/httpx/httpx-0.24.1-py3-none-any.whl (75 kB)
Collecting home-assistant-bluetooth==1.10.0 (from homeassistant==2023.5.4)
  Using cached home_assistant_bluetooth-1.10.0-cp311-cp311-manylinux_2_31_armv7l.whl
Collecting ifaddr==0.1.7 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/ifaddr/ifaddr-0.1.7-py2.py3-none-any.whl (10 kB)
Collecting jinja2==3.1.2 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/jinja2/Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting lru-dict==1.1.8 (from homeassistant==2023.5.4)
  Using cached lru_dict-1.1.8-cp311-cp311-linux_armv7l.whl
Collecting PyJWT==2.6.0 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/pyjwt/PyJWT-2.6.0-py3-none-any.whl (20 kB)
Collecting cryptography==40.0.2 (from homeassistant==2023.5.4)
  Using cached https://mirrors.aliyun.com/pypi/packages/f7/80/04cc7637238b78f8e7354900817135c5a23cf66dfb3f3a216c6d630d6833/cryptography-40.0.2.tar.gz (625 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pyOpenSSL==23.1.0 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/pyopenssl/pyOpenSSL-23.1.0-py3-none-any.whl (57 kB)
Collecting orjson==3.8.10 (from homeassistant==2023.5.4)
  Using cached https://mirrors.aliyun.com/pypi/packages/56/f2/86cd00c33d468ba74427b91bc41a8d050064f5b5b8ac8f5e9a39a0965ace/orjson-3.8.10-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (147 kB)
Requirement already satisfied: pip<23.2,>=21.0 in ./lib/python3.11/site-packages (from homeassistant==2023.5.4) (23.1.2)
Collecting python-slugify==4.0.1 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/python-slugify/python_slugify-4.0.1-py2.py3-none-any.whl (7.0 kB)
Collecting pyyaml==6.0 (from homeassistant==2023.5.4)
  Using cached PyYAML-6.0-cp311-cp311-linux_armv7l.whl
Collecting requests==2.28.2 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/requests/requests-2.28.2-py3-none-any.whl (62 kB)
Collecting typing-extensions<5.0,>=4.5.0 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/typing-extensions/typing_extensions-4.6.3-py3-none-any.whl (31 kB)
Collecting ulid-transform==0.7.2 (from homeassistant==2023.5.4)
  Using cached ulid_transform-0.7.2-cp311-cp311-manylinux_2_31_armv7l.whl
Collecting voluptuous==0.13.1 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/voluptuous/voluptuous-0.13.1-py3-none-any.whl (35 kB)
Collecting voluptuous-serialize==2.6.0 (from homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/voluptuous-serialize/voluptuous_serialize-2.6.0-py3-none-any.whl (6.8 kB)
Collecting yarl==1.9.2 (from homeassistant==2023.5.4)
  Using cached yarl-1.9.2-cp311-cp311-linux_armv7l.whl
Collecting charset-normalizer<4.0,>=2.0 (from aiohttp==3.8.4->homeassistant==2023.5.4)
  Using cached https://mirrors.aliyun.com/pypi/packages/ef/81/14b3b8f01ddaddad6cdec97f2f599aa2fa466bd5ee9af99b08b7713ccd29/charset_normalizer-3.1.0-py3-none-any.whl (46 kB)
Collecting multidict<7.0,>=4.5 (from aiohttp==3.8.4->homeassistant==2023.5.4)
  Using cached multidict-6.0.4-cp311-cp311-linux_armv7l.whl
Collecting frozenlist>=1.1.1 (from aiohttp==3.8.4->homeassistant==2023.5.4)
  Using cached frozenlist-1.3.3-cp311-cp311-linux_armv7l.whl
Collecting aiosignal>=1.1.2 (from aiohttp==3.8.4->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/aiosignal/aiosignal-1.3.1-py3-none-any.whl (7.6 kB)
Collecting pytz (from astral==2.2->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/pytz/pytz-2023.3-py3-none-any.whl (502 kB)
Requirement already satisfied: cffi>=1.12 in ./lib/python3.11/site-packages (from cryptography==40.0.2->homeassistant==2023.5.4) (1.15.1)
Collecting httpcore<0.18.0,>=0.15.0 (from httpx==0.24.1->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/httpcore/httpcore-0.17.2-py3-none-any.whl (72 kB)
Collecting idna (from httpx==0.24.1->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/idna/idna-3.4-py3-none-any.whl (61 kB)
Collecting sniffio (from httpx==0.24.1->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/sniffio/sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting MarkupSafe>=2.0 (from jinja2==3.1.2->homeassistant==2023.5.4)
  Using cached MarkupSafe-2.1.2-cp311-cp311-linux_armv7l.whl
Collecting text-unidecode>=1.3 (from python-slugify==4.0.1->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/text-unidecode/text_unidecode-1.3-py2.py3-none-any.whl (78 kB)
Collecting urllib3<1.27,>=1.21.1 (from requests==2.28.2->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/urllib3/urllib3-1.26.16-py2.py3-none-any.whl (143 kB)
Requirement already satisfied: pycparser in ./lib/python3.11/site-packages (from cffi>=1.12->cryptography==40.0.2->homeassistant==2023.5.4) (2.21)
Collecting h11<0.15,>=0.13 (from httpcore<0.18.0,>=0.15.0->httpx==0.24.1->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/h11/h11-0.14.0-py3-none-any.whl (58 kB)
Collecting anyio<5.0,>=3.0 (from httpcore<0.18.0,>=0.15.0->httpx==0.24.1->homeassistant==2023.5.4)
  Using cached https://www.piwheels.org/simple/anyio/anyio-3.7.0-py3-none-any.whl (80 kB)
Building wheels for collected packages: cryptography
  Building wheel for cryptography (pyproject.toml) ... done
  Created wheel for cryptography: filename=cryptography-40.0.2-cp311-cp311-linux_armv7l.whl size=1507596 sha256=2a240b5125a4ddecd482a395c3c74394d33db01d9b418101c907bef468aa567b
  Stored in directory: /home/homeassistant20230504/.cache/pip/wheels/36/f9/59/9f51a819e2722356285f35987d7fffca5b57b7c04b7fc06da2
Successfully built cryptography
Installing collected packages: voluptuous, text-unidecode, pytz, lru-dict, ifaddr, ciso8601, voluptuous-serialize, urllib3, ulid-transform, typing-extensions, sniffio, pyyaml, python-slugify, PyJWT, orjson, multidict, MarkupSafe, idna, home-assistant-bluetooth, h11, frozenlist, charset-normalizer, certifi, bcrypt, awesomeversion, attrs, atomicwrites-homeassistant, async-timeout, astral, yarl, requests, jinja2, cryptography, anyio, aiosignal, pyOpenSSL, httpcore, aiohttp, httpx, homeassistant
  Attempting uninstall: cryptography
    Found existing installation: cryptography 41.0.1
    Uninstalling cryptography-41.0.1:
      Successfully uninstalled cryptography-41.0.1
Successfully installed MarkupSafe-2.1.2 PyJWT-2.6.0 aiohttp-3.8.4 aiosignal-1.3.1 anyio-3.7.0 astral-2.2 async-timeout-4.0.2 atomicwrites-homeassistant-1.4.1 attrs-22.2.0 awesomeversion-22.9.0 bcrypt-4.0.1 certifi-2023.5.7 charset-normalizer-3.1.0 ciso8601-2.3.0 cryptography-40.0.2 frozenlist-1.3.3 h11-0.14.0 home-assistant-bluetooth-1.10.0 homeassistant-2023.5.4 httpcore-0.17.2 httpx-0.24.1 idna-3.4 ifaddr-0.1.7 jinja2-3.1.2 lru-dict-1.1.8 multidict-6.0.4 orjson-3.8.10 pyOpenSSL-23.1.0 python-slugify-4.0.1 pytz-2023.3 pyyaml-6.0 requests-2.28.2 sniffio-1.3.0 text-unidecode-1.3 typing-extensions-4.6.3 ulid-transform-0.7.2 urllib3-1.26.16 voluptuous-0.13.1 voluptuous-serialize-2.6.0 yarl-1.9.2

First-run ERROR

(homeassistant) homeassistant@raspberrypi:/srv/homeassistant$ hass -v

output


2023-06-04 09:47:18.512 ERROR (MainThread) [homeassistant.setup] Setup failed for analytics: Unable to import component: No module named '_sqlite3'

 Unable to set up dependencies of onboarding. Setup failed for dependencies: analytics
2023-06-04 09:47:18.802 ERROR (MainThread) [homeassistant.setup] Setup failed for onboarding: (DependencyError(...), 'Could not setup dependencies: analytics')
2023-06-04 09:47:18.807 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of frontend. Setup failed for dependencies: onboarding
2023-06-04 09:47:18.813 ERROR (MainThread) [homeassistant.setup] Setup failed for frontend: (DependencyError(...), 'Could not setup dependencies: onboarding')

Unable to set up dependencies of map. Setup failed for dependencies: frontend
2023-06-04 09:47:29.396 ERROR (MainThread) [homeassistant.setup] Setup failed for map: (DependencyError(...), 'Could not setup dependencies: frontend')

2023-06-04 09:47:29.467 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of history. Setup failed for dependencies: recorder
2023-06-04 09:47:29.477 ERROR (MainThread) [homeassistant.setup] Setup failed for history: (DependencyError(...), 'Could not setup dependencies: recorder')
2023-06-04 09:47:29.494 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of my. Setup failed for dependencies: frontend
2023-06-04 09:47:29.508 ERROR (MainThread) [homeassistant.setup] Setup failed for my: (DependencyError(...), 'Could not setup dependencies: frontend')


...
2023-06-04 08:12:58.463 ERROR (SyncWorker_0) [homeassistant.util.package] Unable to install package ha-av==10.0.0: error: subprocess-exited-with-error

Solution

installed manually

pip install ha-av==10.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple


No module named '_sqlite3 in Python 3.11

On debian 11, with Python 3.11.1 I get the following error when loading the script:
No module named β€˜_sqlite3’

With Python 3.10.x it is working as expected.

It looks like the sqlite module is (accidentally) missing in the Windows Python 3.11 installer.

python3
root@raspberrypi:~# python3

Python 3.11.3 (main, Jun  4 2023, 03:07:34) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages']
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/sqlite3/__init__.py", line 57, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.11/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
>>> 

Solution

python3.10 -c β€˜import _sqlite3 as m;print(m.file)’

output

root@raspberrypi:~# python3.10 -c β€˜import _sqlite3 as m;print(m.file)’
/usr/local/lib/python3.10/lib-dynload/_sqlite3.cpython-310-arm-linux-gnueabihf.so

root@raspberrypi:~# python3.11 -c β€˜import random as m;print(m.file)’
/usr/local/lib/python3.11/random.py

root@raspberrypi:~# scp /usr/local/lib/python3.10/lib-dynload/_sqlite3.cpython-310-arm-linux-gnueabihf.so /usr/local/lib/python3.11/lib-dynload/_sqlite3.cpython-311-arm-linux-gnueabihf.so

root@raspberrypi:~# python3.11 -c β€˜import _sqlite3 as m;print(m.file)’
/usr/local/lib/python3.11/lib-dynload/_sqlite3.cpython-311-arm-linux-gnueabihf.so

Solution 1:
sudo cp /usr/local/lib/sql /usr/lib/arm-linux-gnueabihf/
sudo chmod a+x /usr/lib/arm-linux-gnueabihf/sql
https://community.home-assistant.io/t/raspberrypi-ha-core-version-3-27-2-of-sqlite-is-not-supported/352858/16?u=msly
Solution 2:
https://community.home-assistant.io/t/raspberrypi-ha-core-version-3-27-2-of-sqlite-is-not-supported/352858/17?u=msly

Solution 3:
https://community.home-assistant.io/t/raspberrypi-ha-core-version-3-27-2-of-sqlite-is-not-supported/352858/19?u=msly
Solution 4:
https://community.home-assistant.io/t/raspberrypi-ha-core-version-3-27-2-of-sqlite-is-not-supported/352858/6?u=msly

useful links

Python 3.11 installation: some modules are missing

Windows - Python 3.11 - No module named _sqlite3

sqlite3.threadsafety β€” Python 3.11.0 documentation.
https://blog.csdn.net/jaket5219999/article/details/53512071

Did you get the sqlite3 issue resolved?

second-run setup fails

Unable to install package ha-av==10.0.0

Home Assistant 2023.6.
Python 3.11 venv
After each restart I have

hass -v

output

note: This error originates from a subprocess, and is likely not a problem with pip.
2023-07-05 07:31:37.425 INFO (SyncWorker_2) [homeassistant.util.package] Attempting install of ha-av==10.1.0
2023-07-05 07:32:57.051 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package ha-av==10.1.0: error: subprocess-exited-with-error
  
  Γ— Getting requirements to build wheel did not run successfully.
  β”‚ exit code: 1
  ╰─> [29 lines of output]
      Package libavformat was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libavformat.pc'
      to the PKG_CONFIG_PATH environment variable
      No package 'libavformat' found
      Package libavcodec was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libavcodec.pc'
      to the PKG_CONFIG_PATH environment variable
      No package 'libavcodec' found
      Package libavdevice was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libavdevice.pc'
      to the PKG_CONFIG_PATH environment variable
      No package 'libavdevice' found
      Package libavutil was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libavutil.pc'
      to the PKG_CONFIG_PATH environment variable
      No package 'libavutil' found
      Package libavfilter was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libavfilter.pc'
      to the PKG_CONFIG_PATH environment variable
      No package 'libavfilter' found
      Package libswscale was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libswscale.pc'
      to the PKG_CONFIG_PATH environment variable
      No package 'libswscale' found
      Package libswresample was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libswresample.pc'
      to the PKG_CONFIG_PATH environment variable
      No package 'libswresample' found
      pkg-config could not find libraries ['avformat', 'avcodec', 'avdevice', 'avutil', 'avfilter', 'swscale', 'swresample']
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

Γ— Getting requirements to build wheel did not run successfully.
β”‚ exit code: 1
╰─> See above for output.

ffmpeg -version

ffmpeg -version
ffmpeg version 4.3.5-0+deb11u1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 10 (Raspbian 10.2.1-6+rpi1)
configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --arch=arm --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 51.100 / 56. 51.100
libavcodec     58. 91.100 / 58. 91.100
libavformat    58. 45.100 / 58. 45.100
libavdevice    58. 10.100 / 58. 10.100
libavfilter     7. 85.100 /  7. 85.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  7.100 /  5.  7.100
libswresample   3.  7.100 /  3.  7.100
libpostproc    55.  7.100 / 55.  7.100

ffmpeg has no support for python 3.11 yet

On bullseye, do you have libavdevice-dev, libavformat-dev, libavcodec-dev,
libavutil-dev, and libavfilter-dev?

Solution

https://community.home-assistant.io/t/unable-to-install-package-ha-av/466286/31?u=msly

https://github.com/uvjustin/PyAV/compare/v10.1.0…v10.1.1

yes, the sqlite3 issue resolved

1 Like