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

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