Home assistant core python problems

I am struggling to update home assistant core installed using the guide on a rpi3. I think the problem is the virtual user that its installed into.

Normal user (and root) uses pyenv now, but, inside the @homeassistant user its still running python 3.9. I tried installing pyenv inside this user but it gives several errors at the end and even though i manage to pyenv install 3.11.2 checking with python3 still shows 3.9.2

is there some command i should run inside the virtual user to make it update?

EDIT

running this command: eval “$(pyenv init -)”

i managed to get the python3 to finally accept the pyenv. BUT, now i get the following error when trying to upgrade

(homeassistant) homeassistant@raspberrypi:/home/kexan $ pip3 install homeassistant==2023.2.5
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting homeassistant==2023.2.5
  Using cached homeassistant-2023.2.5-py3-none-any.whl (21.7 MB)
Collecting aiohttp==3.8.1
  Using cached aiohttp-3.8.1.tar.gz (7.3 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [84 lines of output]
      *********************
      * Accelerated build *
      *********************
      running dist_info
      creating /tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info
      writing /tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info/dependency_links.txt
      writing requirements to /tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info/requires.txt
      writing top-level names to /tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info/top_level.txt
      writing manifest file '/tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info/SOURCES.txt'
      reading manifest file '/tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      warning: no files found matching 'aiohttp' anywhere in distribution
      warning: no previously-included files matching '*.pyc' found anywhere in distribution
      warning: no previously-included files matching '*.pyd' found anywhere in distribution
      warning: no previously-included files matching '*.so' found anywhere in distribution
      warning: no previously-included files matching '*.lib' found anywhere in distribution
      warning: no previously-included files matching '*.dll' found anywhere in distribution
      warning: no previously-included files matching '*.a' found anywhere in distribution
      warning: no previously-included files matching '*.obj' found anywhere in distribution
      warning: no previously-included files found matching 'aiohttp/*.html'
      no previously-included directories found matching 'docs/_build'
      adding license file 'LICENSE.txt'
      writing manifest file '/tmp/pip-modern-metadata-te3mqej5/aiohttp.egg-info/SOURCES.txt'
      creating '/tmp/pip-modern-metadata-te3mqej5/aiohttp-3.8.1.dist-info'
      Traceback (most recent call last):
        File "/home/homeassistant/.pyenv/versions/3.11.2/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/homeassistant/.pyenv/versions/3.11.2/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/homeassistant/.pyenv/versions/3.11.2/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 377, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 335, in run_setup
          exec(code, locals())
        File "<string>", line 54, in <module>
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/__init__.py", line 108, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 1221, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/command/dist_info.py", line 103, in run
          bdist_wheel = self.get_finalized_command('bdist_wheel')
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 304, in get_finalized_command
          cmd_obj = self.distribution.get_command_obj(command, create)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 860, in get_command_obj
          klass = self.get_command_class(command)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-6noounl4/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 966, in get_command_class
          self.cmdclass[command] = cmdclass = ep.load()
                                              ^^^^^^^^^
        File "/home/homeassistant/.pyenv/versions/3.11.2/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
          module = import_module(match.group('module'))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/homeassistant/.pyenv/versions/3.11.2/lib/python3.11/importlib/__init__.py", line 126, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 940, in exec_module
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "/tmp/pip-build-env-6noounl4/normal/lib/python3.11/site-packages/wheel/bdist_wheel.py", line 28, in <module>
          from .macosx_libfile import calculate_macosx_platform_tag
        File "/tmp/pip-build-env-6noounl4/normal/lib/python3.11/site-packages/wheel/macosx_libfile.py", line 43, in <module>
          import ctypes
        File "/home/homeassistant/.pyenv/versions/3.11.2/lib/python3.11/ctypes/__init__.py", line 8, in <module>
          from _ctypes import Union, Structure, Array
      ModuleNotFoundError: No module named '_ctypes'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

for updating python I find this blog to be most helpful as its also kept up to date.

i´ve tried some steps but keep getting the same error as above. This article creates a new virtual enviorment, wont that reset everything in HA or is it safe to do so?

it wont impact the config directory if that is what you are worried about since its in a separate location. Otherwise it will just redownload all the libraries etc… again under the new python version in the venv location.

me for example I keep my venv in /srv/homeassistant3.10/... and when i update I jsut create a new folder there. My config is located in /home/homeassistant/....

sounds great, ill give it a go and create another venv. Just have to figure out how to invoke that with pyenv instead of downloading, but perhaps thats the same command.

Honestly… use Docker.

It’s going to be a lot easier for you.

1 Like

sadly even setting up HA on a RPI has taken me weeks of research and trial and error. I fear that switching to docker would mean i have to redo the entire process. Can you run a docker AND show the dashboard on the same RPI3b?

i finally got it working, i dont know if it was the extra parts in the guide or simply my last trial and error attempt. but if someone struggles as i did:

Having gotten pyenv to work in the venv, i had installed python 3.11.2 and made it global (as proven by python3 --version) but installing 3.11.0 and making that global instead seemed to fix the issue i had. (SEE COMMENT ABOUT 3.11)

thank you @Tinkerer and @dshokouhi for taking the time to help me.

EDIT: So the installation failed on later points, but i finally found this post:

In it, its made clear that python 3.11 might cause problems since HA doesnt support it yet (dec 22) so i tried 3.10.9 and it seems to work, installation has passed the two dependencies that were the issue (aiohttp and bcrypt)

Yes you can.

Getting HA running in Docker is as complicated as:

  1. Install Docker + Compose
  2. Create the compose file
  3. Run docker compose pull && docker compose up

i will be checking this out tomorrow to see if its worth redoing all the config stuff then because im still stuck with httpaio versions and stuff… thx