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

Pyscript fails to load due toRequirementsNotFound since upgrade to 2025.1.4 #694

Open
tobiderifsch opened this issue Jan 31, 2025 · 2 comments

Comments

@tobiderifsch
Copy link

I've recently upgraded to Homeassistant Core 2025.1.4 and Homeassistant OS 14.2. Since this upgrade my pyscript integration cannot start as long as I have truenas_api_client listed in the requirements.txt file. Unfortunately I don't know which version Core was installed previously but it must've been either 20025.1.2 or 2025.1.3.

This is the stack trace posted into the logs:

Logger: homeassistant.config_entries
Source: config_entries.py:640
First occurred: 10:49:06 PM (1 occurrences)
Last logged: 10:49:06 PM

Error setting up entry pyscript for pyscript
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context
    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(
    ...<8 lines>...
    )
  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: ['truenas_api_client'].

As far as I can tell this package and it's own dependencies (only websocket-client) are up to date and don't conflict with any changes to Homeassistant Core, still something is broken. Other packages could be installed just fine throught the requirements.txt.

Any help is appreciated!

@tobiderifsch
Copy link
Author

So after some experimentation it seems that pip install truenas_api_client is no longer working but instead you need to do pip install git+https://github.com/truenas/api_client.git. However pyscript seemingly can't install packages from github.
Until when I upgraded my homeassistant core version it worked fine with the line truenas_api_client in the requirements.txt and now it's not working anymore... if anyone knows a workaround for this please let me know because I can't figure one out right now.

@orbelico
Copy link

orbelico commented Feb 14, 2025

I have not tried this myself, but you should be able to put the module code into a local folder and make it accessible on the python package path. See https://hacs-pyscript.readthedocs.io/en/latest/reference.html#importing:

One way to do that is in one of your pyscript script files, add this code:

import sys

if "/config/pyscript_modules" not in sys.path:
    sys.path.append("/config/pyscript_modules")

This adds the directory /config/pyscript_modules to Python’s module search path (you should use the correct full path specific to your installation). You will need to set the allow_all_imports configuration parameter to true to allow importing of sys. You can then add modules (files ending in .py) to that folder, which will contain native Python that is compiled when imported (note that none of the pyscript-specific features are available in those modules).

The docs only talk about modules (i.e. single .py files), but it might be worth a try if a package (a folder containing an __init__.py and further files/subfolders) works, too.

  1. Remove truenas_api_client from your requirements.txt
  2. Follow the above steps from the docs
  3. In some other folder on your hard drive, clone the git repo: git clone https://github.com/truenas/api_client.git
    This will create a folder "api_client". Inside you should find the files listed on the github page.
  4. Copy the truenas_api_client subfolder (only that one, it is the actual package) into /config/pyscript_modules (created in step 1.), so it becomes /config/pyscript_modules/truenas_api_client.
  5. Just to be super clear about the dir structure: you should now have a file /config/pyscript_modules/truenas_api_client/__init__.py (and of course further files/folders besides it)
  6. Try again if the import works now.
    Hope that helps.

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

2 participants