Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to 2024.10 causes Pyscript to not load #640

Open
dinki opened this issue Oct 4, 2024 · 8 comments
Open

Upgrade to 2024.10 causes Pyscript to not load #640

dinki opened this issue Oct 4, 2024 · 8 comments

Comments

@dinki
Copy link

dinki commented Oct 4, 2024

I upgraded to 2024.10 and now I am getting errors loading Pyscript. The error I see in the log says:

Logger: homeassistant.config_entries
Source: config_entries.py:594
First occurred: 6:58:54 PM (1 occurrences)
Last logged: 6:58:54 PM

Error setting up entry pyscript for pyscript
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/pyscript/__init__.py", line 280, in async_setup_entry
    await install_requirements(hass, config_entry, pyscript_folder)
  File "/config/custom_components/pyscript/requirements.py", line 297, in install_requirements
    await async_process_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 65, in async_process_requirements
    await _async_get_manager(hass).async_process_requirements(name, requirements)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 264, in async_process_requirements
    self._raise_for_failed_requirements(name, missing)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 292, in _raise_for_failed_requirements
    raise RequirementsNotFound(integration, [req])
homeassistant.requirements.RequirementsNotFound: Requirements for pyscript not found: ['PyDictionary'].

Can someone tell me what I might do to repair this?

@ALERTua
Copy link
Contributor

ALERTua commented Oct 5, 2024

Pyscript has no such requirement as PyDictionary https://github.com/custom-components/pyscript/blob/master/custom_components/pyscript/manifest.json
Maybe the cause is in requirements.txt within your pyscript directory?

@dinki
Copy link
Author

dinki commented Oct 5, 2024

Thanks for the quick response. You are correct. This is what I have in requirements.txt:

wikipedia
PyDictionary

Is there something I need to do to have these installed automatically when the new container is created?

@ALERTua
Copy link
Contributor

ALERTua commented Oct 5, 2024

https://hacs-pyscript.readthedocs.io/en/stable/reference.html#importing starting from "Pyscript can install required Python packages if they are missing". and make sure the modules are installable on the server's Python version.

@dinki
Copy link
Author

dinki commented Oct 5, 2024

If your pyscript code requires particular Python packages that are not already installed by HASS, add a requirements.txt file the /pyscript directory.

Apologies for not being clear. The message above your response is the requirements.txt file I have in my HA /config/pyscript directory. This has worked great for a long time until 2024.10 install. It does not appear that this is operating as it did before. In fact, the container updated last night for the 2024.10.1 release and I am again getting the same error as the 'PyDictionary' module did not install via the requirements.txt.

Hopefully I am not misunderstanding what you are telling me but it does appear that the packages listed in requirements.txt are not being installed when the container updates.

@dinki
Copy link
Author

dinki commented Oct 6, 2024

https://hacs-pyscript.readthedocs.io/en/stable/reference.html#importing starting from "Pyscript can install required Python packages if they are missing". and make sure the modules are installable on the server's Python version.

I hate to try your patience, @ALERTua , but am I not doing what is shown in the docs? It is not working as it did previously where it would install these when necessary.

@MoJo2600
Copy link

MoJo2600 commented Oct 7, 2024

I do think, that I have the same problem.

I do have a requirements.txt file in my module. When I restart homeassistant, the script is not loaded and I get an error where pyscript ist no able to import something. When I open the file and save the file without a change it starts working. It seems to me, that the startup does not wait for the requirements to be installed. So the script is started before the requirements have been installed.

The logs I see are:

2024-10-05 19:51:34.956 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration pyscript which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-10-05 19:51:48.213 INFO (MainThread) [homeassistant.bootstrap] Setting up stage 2: {'input_button', 'pi_hole', 'frigate', 'watchman', 'trace', 'assist_pipeline', 'persistent_notification', 'hardware', 'input_datetime', 'homeassistant_hardware', 'met', 'default_config', 'lovelace', 'fronius', 'co2signal', 'mobile_app', 'ffmpeg', 'hardkernel', 'sun', 'fritzbox', 'homeassistant_alerts', 'schedule', 'tag', 'local_calendar', 'zone', 'brother', 'image_processing', 'telegram_bot', 'sensor', 'script', 'blueprint', 'mqtt', 'stream', 'hue', 'light', 'stt', 'logbook', 'analytics', 'input_select', 'fritz', 'hacs', 'camera', 'input_number', 'diagnostics', 'application_credentials', 'switch', 'notify', 'wake_word', 'media_source', 'input_text', 'config', 'nut', 'esphome', 'automation', 'adaptive_lighting', 'meross_cloud', 'philips_js', 'counter', 'meross_lan', 'my', 'energy', 'influxdb', 'dlna_dms', 'forecast_solar', 'person', 'search', 'tts', 'scene', 'pyscript', 'zha', 'moonraker', 'open_epaper_link', 'image_upload', 'shelly', 'map', 'template', 'google', 'fritzbox_callmonitor', 'backup', 'file_upload', 'homeassistant_sky_connect', 'onboarding', 'synology_dsm', 'openweathermap', 'device_automation', 'ipp', 'google_tasks', 'intent', 'radio_browser', 'system_health', 'conversation', 'history', 'cast', 'unifi', 'timer', 'input_boolean'}
2024-10-05 19:52:04.650 INFO (MainThread) [homeassistant.setup] Setting up pyscript
2024-10-05 19:52:04.656 INFO (MainThread) [homeassistant.setup] Setup of domain pyscript took 0.00 seconds
2024-10-05 19:52:04.674 DEBUG (MainThread) [custom_components.pyscript] Version '10.4.0' for package 'pillow' detected in '['/config/pyscript/modules/epaperdashboard/requirements.txt']' will be ignored because it is already installed
2024-10-05 19:52:04.674 DEBUG (MainThread) [custom_components.pyscript] No new packages to install
2024-10-05 19:52:04.718 ERROR (MainThread) [custom_components.pyscript.modules.epaperdashboard] Exception in </config/pyscript/modules/epaperdashboard/__init__.py> line 1:
2024-10-05 19:52:04.719 ERROR (MainThread) [custom_components.pyscript.global_ctx] module_import: failed to load module epaperdashboard, ctx = modules.epaperdashboard, path = /config/pyscript/modules/epaperdashboard/__init__.py
2024-10-05 19:52:04.719 ERROR (MainThread) [custom_components.pyscript.apps.epaper_calendar_small] Exception in </config/pyscript/modules/epaperdashboard/__init__.py> line 1:
2024-10-05 19:52:04.722 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/epaper-dashboard.py
2024-10-05 19:52:04.730 DEBUG (SyncWorker_0) [custom_components.pyscript] watchdog init path=/config/pyscript
2024-10-05 19:52:04.732 DEBUG (MainThread) [custom_components.pyscript] watchdog started job and task folder=/config/pyscript
2024-10-05 19:52:53.140 DEBUG (MainThread) [custom_components.pyscript] adding state changed listener and starting global contexts
2024-10-05 19:52:53.149 DEBUG (SyncWorker_4) [custom_components.pyscript] watchdog startup

@dinki
Copy link
Author

dinki commented Oct 9, 2024

https://hacs-pyscript.readthedocs.io/en/stable/reference.html#importing starting from "Pyscript can install required Python packages if they are missing". and make sure the modules are installable on the server's Python version.

Removing both the script and the 'PyDictionary' line from requirements.txt allows for the integration to load now. Fortunately I am not using that script and the dependency is not necessary for others but something is definitely weird. I do have 'wikipedia' as the only other line in requirements.txt so perhaps it is an issue with 'PyDictionary' specifically.

@ognacy
Copy link

ognacy commented Oct 15, 2024

There is definitely something wrong. Following the 2024.10 update my script is also not loading on startup, and it does not seem to be related to requirements.txt.

My script, among other things, sets various input variables. When that script initializes on HA load, it throws an exception:

2024-10-15 06:39:04.147 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/light_motion.py 2024-10-15 06:39:04.153 ERROR (MainThread) [custom_components.pyscript.file.lights] Exception in </config/pyscript/lights.py> line 10: input_text.set_value(entity_id="input_text.strtext", value='a\nb') ^ NameError: name 'input_text.set_value' is not defined

When I re-initialize this script a minute later by saving the file, it runs fine.

I am not familiar with the inner workings of pyscript yet, but it appears to me that there is indeed a bug/race condition with loading other (core?) pyscript modules which declare the dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants