I recently got started with AppDaemon (running it as a Hass.io add on) and ran into the issue of not being able to install dependencies that I wanted to import into my apps.
Because I did not want to adjust and rebuild the AppDaemon add on (Dockerfile) each time I wanted to try out/use a dependency, I’ve written a small app that does the installation of dependencies for me.
Posting it here because it might come in helpful for others in the future. I do however think that adjusting and rebuilding the AppDaemon add on is the more correct way of doing this.
Let me know if there’s another way!
import appdaemon.appapi as appapi
import subprocess
PACKAGES = ['guessit',
'tmdbsimple']
class DepeInstaller(appapi.AppDaemon):
def initialize(self):
self.log("Installing packages")
for package in PACKAGES:
self.log("Installing {}".format(package))
self.install(package)
def install(self, package):
# https://github.com/pypa/pip/issues/2553
subprocess.call(['pip3', 'install', package])
Once configured, it should give some output like the following
2017-11-19 11:17:36.590848 INFO Reloading Module: /config/appdaemon/apps/depe_installer.py
2017-11-19 11:17:36.607065 INFO Loading Object depe_installer using class DepeInstaller from module depe_installer
2017-11-19 11:17:36.645915 INFO depe_installer: Installing packages
2017-11-19 11:17:36.660491 INFO depe_installer: Installing guessit
Requirement already satisfied: guessit in /usr/lib/python3.6/site-packages
Requirement already satisfied: rebulk>=0.9.0 in /usr/lib/python3.6/site-packages (from guessit)
Requirement already satisfied: babelfish>=0.5.5 in /usr/lib/python3.6/site-packages (from guessit)
Requirement already satisfied: python-dateutil in /usr/lib/python3.6/site-packages (from guessit)
Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from rebulk>=0.9.0->guessit)
2017-11-19 11:17:41.645966 INFO depe_installer: Installing tmdbsimple
Requirement already satisfied: tmdbsimple in /usr/lib/python3.6/site-packages
Requirement already satisfied: requests in /usr/lib/python3.6/site-packages (from tmdbsimple)
Requirement already satisfied: idna<2.7,>=2.5 in /usr/lib/python3.6/site-packages (from requests->tmdbsimple)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3.6/site-packages (from requests->tmdbsimple)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.6/site-packages (from requests->tmdbsimple)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/lib/python3.6/site-packages (from requests->tmdbsimple)