AppDaemon on Rasbian venv installaiton, ImportError: No module named 'pkg_resources' please help

I installed on Raspian venv Appdaemon following instruction from @gpbenton (very clear thanks) but later after it I am not able to test app hello.py because I dont find path such as appdaemon -c /home/homeassistant/conf or mine that I supposed to be /home/homeassistant/appdaemon_venv/bin/appdaemon

I created /apps directory and hello.py from http://appdaemon.readthedocs.io/en/stable/INSTALL.html

The error I received is:

Traceback (most recent call last):
  File "/usr/local/bin/appdaemon", line 7, in <module>
    from appdaemon.admain import main
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/admain.py", line 2, in <module>
    from pkg_resources import parse_version
ImportError: No module named 'pkg_resources'

my installation was:

pi@raspberrypi:~ $ sudo su -s /bin/bash -l homeassistant
pwd
/home/homeassistant
(homeassistant) homeassistant@raspberrypi:~ $ mkdir appdaemon_venv
(homeassistant) homeassistant@raspberrypi:~ $ cd appdaemon_venv
(homeassistant) homeassistant@raspberrypi:~/appdaemon_venv $ python3 -m venv .
(homeassistant) homeassistant@raspberrypi:~/appdaemon_venv $ source bin/activate
(appdaemon_venv) homeassistant@raspberrypi:~/appdaemon_venv $ pip3 install wheel
Collecting wheel
Installing collected packages: wheel
Successfully installed wheel-0.31.1
(appdaemon_venv) homeassistant@raspberrypi:~/appdaemon_venv $ pip3 install appdaemon
(appdaemon_venv) homeassistant@raspberrypi:~/appdaemon_venv $ which appdaemon
/home/homeassistant/appdaemon_venv/bin/appdaemon
(appdaemon_venv) homeassistant@raspberrypi:~/appdaemon_venv $ appdaemon -v
appdaemon 3.0.1
(appdaemon_venv) homeassistant@raspberrypi:~/appdaemon_venv $ source appdaemon_venv/bin/activate
(appdaemon_venv) homeassistant@raspberrypi:~ $

My intention is install HADashboard and use AppDaemon for automation
thanks in advance

i recently did a new install from appdaemon in a venv, and i used the conf dir i already had.
but checking now there is no new conf dir anywhere, so you can create it everywhere you like.

in the dir conf you need:
appdaemon.yaml (with the configuration)
apps. subdir (to contain your apps and apps.yaml)
dashboards subdir (default location, can be replaced)
custom_css subdir (optional for custom skins)
custom_widgets subdir (optional)
compiled subdir (with subdirs css, javascript and html)

i did search for your error and it seems there are several reasons and solutions for it.

here you can find out more about it:

Hi Rene,

I created directories and sub-directories for AppDaemon but still continue with problem, I am on way-end because there is not clear reason about problem as your link. do you have any another suggestion.
there is my set up below

thanks in advance,

pi@raspberrypi:/home/homeassistant/.homeassistant/conf $ ls
appdaemon.yaml  apps.  compiled  custom_css  custom_widgets  dashboard
pi@raspberrypi:/home/homeassistant/.homeassistant/conf $ cd compiled/
pi@raspberrypi:/home/homeassistant/.homeassistant/conf/compiled $ ls
css  html  javascript
pi@raspberrypi:/home/homeassistant/.homeassistant/conf/compiled $ cd ..
pi@raspberrypi:/home/homeassistant/.homeassistant/conf $ cd apps./
pi@raspberrypi:/home/homeassistant/.homeassistant/conf/apps. $ ls
apps.yaml  hello.py
pi@raspberrypi:/home/homeassistant/.homeassistant/conf/apps. $ 

also here is my appdaemon.yaml

log:
  logfile: STDOUT
  errorfile: STDERR
appdaemon:
  disable_app: 1
  threads: 10
  app_dir: /conf/apps.
  plugins:
    HASS:
      type: hass
      ha_url: http://192.168.0.100:8123
      ha_key: Password
hadashboard:
  dash_url: http://192.168.0.100:5050
  dash_dir: /conf/dashboards

This looks like appdaemon was not running from within the virtual environment. You need to either start it by running appdaemon after activating the virtual environment, or specify the path to appdaemon inside the venv directory.

Hi gpbenton,

I activated the appdaemon in virtual environment again but it does not start the service. the error is different from begining.
I see the error FileNotFoundError: [Errno 2] No such file or directory: '/home/homeassistant/conf/appdaemon.yaml' but I cannot track from which report error. The correct path is /home/homeassistant/.homeassistant/conf
complete log display is

thanks in advance

pi@raspberrypi:/home/homeassistant/appdaemon_venv $ source bin/activate
(appdaemon_venv) pi@raspberrypi:/home/homeassistant/appdaemon_venv $ sudo systemctl start [email protected]
(appdaemon_venv) pi@raspberrypi:/home/homeassistant/appdaemon_venv $ appdaemon -c /home/homeassistant/conf
Traceback (most recent call last):
  File "/home/homeassistant/appdaemon_venv/bin/appdaemon", line 11, in <module>
    sys.exit(main())
  File "/home/homeassistant/appdaemon_venv/lib/python3.5/site-packages/appdaemon/admain.py", line 375, in main
    admain.main()
  File "/home/homeassistant/appdaemon_venv/lib/python3.5/site-packages/appdaemon/admain.py", line 162, in main
    with open(config_file_yaml, 'r') as yamlfd:
FileNotFoundError: [Errno 2] No such file or directory: '/home/homeassistant/conf/appdaemon.yaml'
(appdaemon_venv) pi@raspberrypi:/home/homeassistant/appdaemon_venv $ sudo systemctl status [email protected]
â—Ź [email protected] - AppDaemon
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2018-06-03 00:46:54 CST; 1min 12s ago
  Process: 25239 ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/appdaemon_venv/bin (code=exited, status=1/FAILURE)
 Main PID: 25239 (code=exited, status=1/FAILURE)

Jun 03 00:46:54 raspberrypi systemd[1]: Started AppDaemon.
Jun 03 00:46:54 raspberrypi appdaemon[25239]: Traceback (most recent call last):
Jun 03 00:46:54 raspberrypi appdaemon[25239]:   File "/usr/local/bin/appdaemon", line 7, in <module>
Jun 03 00:46:54 raspberrypi appdaemon[25239]:     from appdaemon.admain import main
Jun 03 00:46:54 raspberrypi appdaemon[25239]:   File "/usr/local/lib/python3.5/dist-packages/appdaemon/admain.py", line 2, in
Jun 03 00:46:54 raspberrypi appdaemon[25239]:     from pkg_resources import parse_version
Jun 03 00:46:54 raspberrypi appdaemon[25239]: ImportError: No module named 'pkg_resources'
Jun 03 00:46:54 raspberrypi systemd[1]: [email protected]: Main process exited, code=exited, status=1/FAILURE
Jun 03 00:46:54 raspberrypi systemd[1]: [email protected]: Unit entered failed state.
Jun 03 00:46:54 raspberrypi systemd[1]: [email protected]: Failed with result 'exit-code'.

thats the first thing i notice.
you try to start appdaemon 2 times on different ways.

you dont want to start AD as a service when you dont have it installed and working correctly.

second thing i notice:

you have your configuration placed in “/home/homeassistant/.homeassistant/conf”

obviously then this “appdaemon -c /home/homeassistant/conf” wont work

so first things first.

go inside the venv
start AD with
appdaemon -c /home/homeassistant/.homeassistant/conf

and see what error you get.

Hi Rene,

For your suggestion I confirmed that AD is correctly installed. I found some warning about rights on directories. do the cause issues on AD service?
it is on directories css and javascript which belong to AD configuration.

(homeassistant) homeassistant@raspberrypi:~/.homeassistant $ source /home/homeassistant/appda                                                                                                emon_venv/bin/activate
(appdaemon_venv) homeassistant@raspberrypi:~/.homeassistant $ appdaemon -c /home/homeassistan                                                                                                t/conf
2018-06-03 15:59:56.273367 INFO AppDaemon Version 3.0.1 starting
2018-06-03 15:59:56.274325 INFO Configuration read from: /home/homeassistant/conf/appdaemon.y                                                                                                aml
2018-06-03 15:59:56.279223 INFO AppDaemon: Starting Apps
2018-06-03 15:59:56.280703 WARNING config_dir: /home exists, but is not writeable, owner: roo                                                                                                t
2018-06-03 15:59:56.293509 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from mo                                                                                                dule hassplugin
2018-06-03 15:59:56.354999 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-06-03 15:59:56.355937 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-06-03 15:59:56.356832 INFO Starting Dashboards
2018-06-03 15:59:56.361723 WARNING css: /home exists, but is not writeable, owner: root
2018-06-03 15:59:56.364319 WARNING javascript: /home exists, but is not writeable, owner: roo                                                                                                t
2018-06-03 15:59:56.379564 INFO API is disabled
2018-06-03 15:59:56.397035 INFO AppDaemon: HASS: Connected to Home Assistant 0.70.1
2018-06-03 15:59:56.437371 INFO AppDaemon: Got initial state from namespace default
2018-06-03 15:59:58.675302 INFO AppDaemon: Reading config
2018-06-03 15:59:58.682698 INFO AppDaemon: /home/homeassistant/conf/apps/apps.yaml added or m                                                                                                odified
2018-06-03 15:59:58.683680 INFO AppDaemon: /home/homeassistant/conf/apps/apps.yaml added or m                                                                                                odified
2018-06-03 15:59:58.684411 INFO AppDaemon: App 'hello_world' added
2018-06-03 15:59:58.685275 INFO AppDaemon: Adding /home/homeassistant/conf/apps to module imp                                                                                                ort path
2018-06-03 15:59:58.686638 INFO AppDaemon: Loading App Module: /home/homeassistant/conf/apps/                                                                                                hello.py
2018-06-03 15:59:58.718796 INFO AppDaemon: Initializing app hello_world using class HelloWorl                                                                                                d from module hello
2018-06-03 15:59:58.952853 INFO hello_world: Hello from AppDaemon
2018-06-03 15:59:58.956587 INFO hello_world: You are now ready to run Apps!
2018-06-03 15:59:58.958875 INFO AppDaemon: App initialization complete
^C
2018-06-03 16:02:57.080531 INFO Keyboard interrupt
2018-06-03 16:02:57.098974 INFO AppDaemon: HASS: Disconnecting from Home Assistant
2018-06-03 16:02:57.204007 INFO AppDaemon: Removing module /home/homeassistant/conf/apps/hell                                                                                                o.py
2018-06-03 16:02:57.205153 INFO AppDaemon: Terminating hello_world
2018-06-03 16:02:57.207875 INFO AppDeamon Exited

The service should be started for using in HADashboard, I tried to add the service after it.
It failed to be load as a service for systemctl.

pi@raspberrypi:~ $ cat /etc/systemd/system/[email protected]
[Unit]
Description=AppDaemon
[email protected]
[Service]
Type=simple
User=homeassistant
ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/conf
[Install]
WantedBy=multi-user.target

It display this log when failed this message. how can be configured a service in venv since systemctl is configured with root user and AD is configured into homeassistant --> (homeassistant) homeassistant@raspberrypi:~/appdaemon_venv $ source bin/activate

pi@raspberrypi:~ $ systemctl status [email protected]
â—Ź [email protected] - AppDaemon
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: e
   Active: failed (Result: exit-code) since Sun 2018-06-03 16:07:01 CST; 1min 31s ago
  Process: 338 ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/conf (code=exited, s
 Main PID: 338 (code=exited, status=1/FAILURE)

Jun 03 16:07:01 raspberrypi systemd[1]: Started AppDaemon.
Jun 03 16:07:01 raspberrypi appdaemon[338]: Traceback (most recent call last):
Jun 03 16:07:01 raspberrypi appdaemon[338]:   File "/usr/local/bin/appdaemon", line 7, in <mo
Jun 03 16:07:01 raspberrypi appdaemon[338]:     from appdaemon.admain import main
Jun 03 16:07:01 raspberrypi appdaemon[338]:   File "/usr/local/lib/python3.5/dist-packages/ap
Jun 03 16:07:01 raspberrypi appdaemon[338]:     from pkg_resources import parse_version
Jun 03 16:07:01 raspberrypi appdaemon[338]: ImportError: No module named 'pkg_resources'
Jun 03 16:07:01 raspberrypi systemd[1]: [email protected]: Main process exited, cod
Jun 03 16:07:01 raspberrypi systemd[1]: [email protected]: Unit entered failed stat
Jun 03 16:07:01 raspberrypi systemd[1]: [email protected]: Failed with result 'exit

the right warning is about being the home directory not writable.
thats quite normal and shouldnt be a problem.
appdaemon seems to be working as expected.

i would love to help you with the service, but i never start AD as a service. (or anything else)

i guess somehow you need to tell the service that it needs to go into the venv. before executing.
maybe that @gpbenton can help with that part.

Hi Rene,

for HADashboard is not necessary that AD started as a service?

thanks for your help

no nothing is really neccesary to start as service.

i have normally a terminal running on my device that started AD.
you can also run it as a daemon with the -d option.
in that case the terminal can be closed.

i dont run HA as service either :wink:

the only thing is that when you restart your device you need to restart the programs manually.

I have running HA as a service and also I was trying to AD also runs for HADashboard.
maybe @gpbenton could help us.

thanks guys.

This shows the location of your appdaemon command within the vm and should be in the exec: line of the systemd .service file, which must also specify user: homeassistant. If in doubt, post your .service file.

1 Like

hi @gpbenton @ReneTode

It happened that I create venv for AD into HA’s venv, when I tried to run AD as a service somehow modules failed and it does not start.
After gave many turns on problem I figured it out that I have to create out HA’s venv the AD’s venv so it was very easy starting it as a service.

thanks for your help, suggestion and time.

DH

2 Likes