AppDaemon + docker - How to import module

I am trying to use pushbullet and MySQLdb in one of the my AppDaemon app but not sure how to import modules. I am getting error like this:

ModuleNotFoundError: No module named ‘MySQLdb’
ModuleNotFoundError: No module named ‘pushbullet’

My python file has import as shown below:

import pushbullet
import MySQLdb

Any idea?

Basically I need access to the python module(s) inside the docker container application which are installed at the system level. If not possible then how do I make sure that gets installed when I run first time docker AppDaemon?

I think what you need to do is create your own image from the official appdaemon image, and in the docker file add the modules you need using pip.

But I don’t use Docker for appdaemon, so I have no experience in doing it.

Edit A Dockerfile something like this

FROM acockburn/appdaemon:latest

RUN pip install pushbullet MySQLdb
1 Like

Nice. Let me try that. I guess I will have to clone dockerfile and then modify it add those install lines.
Not sure it’s a good idea as when next release dockerfile gets changes I will have to make changes again.
Hope there is a way to pass folder location using -v (volume ) command line to use that inside docker image.
I am new to docker so I have no idea what is better (if not best) way to do it.

But for now, I can try what you suggested, appreciate it, thanks.

problems like this is what made me decide not to use something like docker.
i think you need to look on google how to use python applications from 1 docker inside another docker.

but my gut says me that the way that @gpbenton has given you is the way you need to work.
and you are right that that means that you need to do it over and over with every update.

edit: and maybe next time use appdaemon and not third party integrations, could be that you get faster and more response.

Once you have your Dockerfile written, I don’t think you will have to do anything other than build the image for each release. Docker will fetch the new official appdaemon image and then follow your additional build instructions to build a new image.

thanks for correcting me.
i havent read enough about it to know how it exactly works so i thought you had to recreate after an update, and that the image came with the build instructions in it.

Yeah, this is like catch 22.
I am trying to avoid dependency conflicts with HA and AppDaemon (as of now there is none!).
I am running latest HA and AppDaemon (v1.3.6) at system without Virtual or Docker but thought I will try latest AppDaemon using docker to use dashboards. And dashboards are working really nice without my old AppDaemon apps. In order to move those apps to docker instance I need those additional imports in docker image.
May be @acockburn has some better idea.

And I guess Docker VS Virtualenv is also a big discussion topic:

there will probably never be. Andrew even follows HA with the python installation.
so for me that means that if i want to stay up to date with AD (and i am trying to help andrew where i can, so i need to :wink: ) I also must do HA updates once in a while even if i dont want to.

the 2 programms are to close not to be able to work in the same environment.
and then i need to mention that in the background andrew is working on integrating AD into HA, what means that in the future they never will have conflicts :wink:

so if thats your reason for using docker or venv, i would say, let it go and dont worry about it.

i have it all running fine without docker, without venv at all.
on my PI runs:
Dashboard (obvious)
FTP server
a webcam
and a bunch of other stuff i dont use anymore like GH and alexa

untill now i had never any conflicts.

Thanks a lot for lots of good information and such quoted above which will solve my big issue of connecting my secured HA without going out to DNS resolve my HA url and duckdns certificate issue. I know NGINX can solve this but I tried one time and didn’t get it work on Ubuntu.

I will spend some time to upgrade main instance of AppDaemon on Ubuntu to avoid docker.
Thanks again.

1 Like

add a requirements.txt to your conf directory and the start script in the container will pull them in.