home-assistant / developers.home-assistant

Developers website for Home Assistant.

Home Page:https://developers.home-assistant.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Development Environment - errors when following documentation

bogd opened this issue · comments

I am trying to follow the instructions for setting up a development environment (on Linux, Ubuntu 22.04), and I am encountering multiple issues:

  1. When setting up the core dependencies, the package libavresample-dev does not exist. Based on comments in other threads, I replaced it with libswresample-dev - but I was unable to confirm that this is the correct solution.
  2. When running script/setup, the script exits with an error:
Requirement already satisfied: h11<0.15,>=0.13 in ./venv/lib/python3.10/site-packages (from httpcore<0.19.0,>=0.18.0->httpx>=0.21.0->respx==0.20.2->-r requirements_test.txt (line 33)) (0.14.0)
pre-commit installed at .git/hooks/pre-commit

Usage:   
  /home/bogd/hass-core/venv/bin/python3 -m pip install [options] <requirement specifier> [package-index-options] ...
  /home/bogd/hass-core/venv/bin/python3 -m pip install [options] -r <requirements file> [package-index-options] ...
  /home/bogd/hass-core/venv/bin/python3 -m pip install [options] [-e] <vcs project url> ...
  /home/bogd/hass-core/venv/bin/python3 -m pip install [options] [-e] <local project path> ...
  /home/bogd/hass-core/venv/bin/python3 -m pip install [options] <archive url/path> ...

no such option: --config-settings

As far as I can tell, this is caused by line 27 of the script:

python3 -m pip install -e . --config-settings editable_mode=compat --constraint homeassistant/package_constraints.txt
  1. When trying to set up the integration scaffold, the script.scaffold module exits with:
(venv) bogd@dev-hass:~/hass-core$ python3 -m script.scaffold integration
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/bogd/hass-core/script/scaffold/__main__.py", line 7, in <module>
    from . import docs, error, gather_info, generate
  File "/home/bogd/hass-core/script/scaffold/gather_info.py", line 4, in <module>
    from homeassistant.util import slugify
  File "/home/bogd/hass-core/homeassistant/util/__init__.py", line 16, in <module>
    from .dt import as_local, utcnow
  File "/home/bogd/hass-core/homeassistant/util/dt.py", line 17, in <module>
    UTC = dt.UTC
AttributeError: module 'datetime' has no attribute 'UTC'
  1. (possibly as a result of 2?) - there is no hass command in my venv:
(venv) bogd@dev-hass:~/hass-core$ hass
Command 'hass' not found, did you mean:
  command 'cass' from snap cass (0.17.2)
  command 'sass' from deb ruby-sass (3.7.4-5)
  command 'pass' from deb pass (1.7.4-5)
  command 'ass' from deb irpas (0.10-9)
See 'snap info <snapname>' for additional versions.

This is on a fresh install of Ubuntu 22.04, with Python 3.10.12.

Is there something I missed in the documentation? Can anyone point me in the right direction?

Thank you!

After looking more carefully through the docs, I found this easily-overlooked line: Make sure your Python version is 3.11

And, unfortunately, the default Python version on Ubuntu is 3.10 (also, it is the latest one available in the official APT repos).

sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.12 python3.12-venv python3.12-dev
sudo rm /usr/bin/python3
sudo ln -s /usr/bin/python3.12 /usr/bin/python3

I also had to install some additional prerequisites (used during building the wheels):

sudo apt install -y cmake

With this change, script/setup runs successfully to the end, and I do have a hass command in the venv.

The script.scaffold module starts, but crashes with another error, due to another missing requirement (numpy).

# From within the venv
pip3 install numpy

And with this, the scaffold runs successfully, fixing (almost) all the problems I mentioned. There is still the issue of libavresample-dev missing, but hopefully the replacement suggested in other threads will work.

I will close the issue, but leave these details here - hopefully they will help others facing the same problems. Considering the fact that there are both threads and issues mentioning that "there is no 'hass' command", I am guessing I was not the first one encountering them :)