Hassio appdaemon 4 import

Hi, have searched the web and this forum to try and find how a get appdaemon to install a python package. The import on my python app fails as it can’t find the import. I found some reference to


python_packages:
  - httplib2

but it doesn’t seem to work in either appdaemon .yaml or apps.yaml
Please advise where I tell appdaemon that I want top import a python package.
Welcome any help,
Cheers David

Just make a text file named requirements.txt and put it in your conf folder, same folder where your appdaemon.yaml is.

Then list the python packages in the text file with the required version, i.e.

httplib2==0.18.1

Appdaemon will pip install them on startup.

See here: https://appdaemon.readthedocs.io/en/latest/DOCKER_TUTORIAL.html?highlight=requirements.txt#adding-dependencies

Thanks for you fast reply Tomas.
Have tried adding requirements.txt containing the single line you suggested
Have placed that in the same folder as the appdaemon.yaml
have restarted appdaemon and tried restarting Home Assistant fully - unfortunately it still errors:

2020-11-06 09:56:46.204809 WARNING Error: ------------------------------------------------------------
2020-11-06 09:56:46.203230 WARNING Error: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/app_management.py", line 875, in check_app_updates
    await utils.run_in_executor(self, self.read_app, mod["name"], mod["reload"])
  File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 290, in run_in_executor
    response = future.result()
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.8/site-packages/appdaemon/app_management.py", line 668, in read_app
    self.modules[module_name] = importlib.import_module(module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1014, in _gcd_import
  File "", line 991, in _find_and_load
  File "", line 975, in _find_and_load_unlocked
  File "", line 671, in _load_unlocked
  File "", line 783, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/config/appdaemon/apps/hello.py", line 3, in 
    import httplib2
ModuleNotFoundError: No module named 'httplib2'

2020-11-06 09:56:46.196185 WARNING Error: ------------------------------------------------------------
2020-11-06 09:56:46.194905 WARNING Error: Unexpected error loading module: /config/appdaemon/apps/hello.py:
2020-11-06 09:56:46.193369 WARNING Error: ------------------------------------------------------------

I am running version 0.117.1of HA and AppDaemon 4 version: 0.3.1
To test I have merely added the import to the hello.py:

import appdaemon.plugins.hass.hassapi as hass

import httplib2
#
# Hellow World App
#
# Args:
#

class HelloWorld(hass.Hass):

  def initialize(self):
     self.log("Hello from AppDaemon")
     self.log("You are now ready to run Apps!")

Thanks for your help again - there must be a simple answer
Cheers David

Found the answer: for anyone trying to import Python packages on AppDaemon 4 under HASSIO.

  • In Hassio go to supervisor (menu on left hand side) and click on the add-ons AppDaemon 4
  • at the top of the page there is a configuration tab - click this
  • here you can add python packages - for example:
system_packages: []
python_packages:
  - httplib2==0.18.1
  - untangle
init_commands: []

hope this helps someone.
Cheers David