{"action":"created","issue":{"url":"https://api.github.com/repos/Jerrkawz/GarageQTPi/issues/31","repository_url":"https://api.github.com/repos/Jerrkawz/GarageQTPi","labels_url":"https://api.github.com/repos/Jerrkawz/GarageQTPi/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/Jerrkawz/GarageQTPi/issues/31/comments","events_url":"https://api.github.com/repos/Jerrkawz/GarageQTPi/issues/31/events","html_url":"https://github.com/Jerrkawz/GarageQTPi/issues/31","id":450847965,"node_id":"MDU6SXNzdWU0NTA4NDc5NjU=","number":31,"title":"Can't find installed libraries when running as a service","user":{"login":"bg1000","id":38083150,"node_id":"MDQ6VXNlcjM4MDgzMTUw","avatar_url":"https://avatars1.githubusercontent.com/u/38083150?v=4","gravatar_id":"","url":"https://api.github.com/users/bg1000","html_url":"https://github.com/bg1000","followers_url":"https://api.github.com/users/bg1000/followers","following_url":"https://api.github.com/users/bg1000/following{/other_user}","gists_url":"https://api.github.com/users/bg1000/gists{/gist_id}","starred_url":"https://api.github.com/users/bg1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bg1000/subscriptions","organizations_url":"https://api.github.com/users/bg1000/orgs","repos_url":"https://api.github.com/users/bg1000/repos","events_url":"https://api.github.com/users/bg1000/events{/privacy}","received_events_url":"https://api.github.com/users/bg1000/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2019-05-31T15:12:04Z","updated_at":"2019-06-17T19:56:47Z","closed_at":null,"author_association":"NONE","body":"I wired things up in my garage and then ran a couple of test scripts to verify the wiring and GPIO numbers were as expected.\r\n\r\nI followed the installation instructions in README.md.\r\nRunning the app from the command line (python main.py) works exactly as expected with no errors.  I enabled discovery and was also able to add the garage cover to the HA front end. I can open and close the door and the icon changes as expected.\r\n\r\nI ran `sudo bash autostart_systemd.sh` which ran without error.  On reboot I see the following in syslog:\r\n\r\n`May 30 19:45:52 raspberrypi python[415]: Traceback (most recent call last):\r\nMay 30 19:45:52 raspberrypi python[415]:   File \"/home/pi/GarageQTPi/main.py\", line 3, in <module>\r\nMay 30 19:45:52 raspberrypi python[415]:     import yaml\r\nMay 30 19:45:52 raspberrypi python[415]: ImportError: No module named yaml\r\nMay 30 19:45:52 raspberrypi systemd[1]: garageqtpi@root.service: Main process exited, code=exited, status=1/FAILURE\r\nMay 30 19:45:52 raspberrypi systemd[1]: garageqtpi@root.service: Unit entered failed state.\r\nMay 30 19:45:52 raspberrypi systemd[1]: garageqtpi@root.service: Failed with result 'exit-code'.`\r\n\r\nThis repeats every 3 seconds when the service is restarted.  It seems that when running as a service that python can not find the libraries that were installed via pip install -r requirements.txt.  I gather this has something to do with how sys.path is set but didn't completely work through that.\r\n\r\nAfter some research I found this post on stack exchange which describes the exact same issue (different library):\r\nhttps://stackoverflow.com/questions/38527235/running-python-script-via-systemd-fails-to-load-module\r\n\r\nThe answer in post 8 is to install the libraries via sudo -H pip install -r requirements.txt\r\nThings work as expected now. I am not 100% certain if this is something specific to how my environment is setup or if others might run into the same issue.\r\n"},"comment":{"url":"https://api.github.com/repos/Jerrkawz/GarageQTPi/issues/comments/502827869","html_url":"https://github.com/Jerrkawz/GarageQTPi/issues/31#issuecomment-502827869","issue_url":"https://api.github.com/repos/Jerrkawz/GarageQTPi/issues/31","id":502827869,"node_id":"MDEyOklzc3VlQ29tbWVudDUwMjgyNzg2OQ==","user":{"login":"tagno25","id":8331767,"node_id":"MDQ6VXNlcjgzMzE3Njc=","avatar_url":"https://avatars1.githubusercontent.com/u/8331767?v=4","gravatar_id":"","url":"https://api.github.com/users/tagno25","html_url":"https://github.com/tagno25","followers_url":"https://api.github.com/users/tagno25/followers","following_url":"https://api.github.com/users/tagno25/following{/other_user}","gists_url":"https://api.github.com/users/tagno25/gists{/gist_id}","starred_url":"https://api.github.com/users/tagno25/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tagno25/subscriptions","organizations_url":"https://api.github.com/users/tagno25/orgs","repos_url":"https://api.github.com/users/tagno25/repos","events_url":"https://api.github.com/users/tagno25/events{/privacy}","received_events_url":"https://api.github.com/users/tagno25/received_events","type":"User","site_admin":false},"created_at":"2019-06-17T19:56:47Z","updated_at":"2019-06-17T19:56:47Z","author_association":"CONTRIBUTOR","body":"#32 should fix the issue, please try the changes after removing the old/incorrect service using the commands below, and report back.\r\n\r\n```\r\nsystemctl disable garageqtpi@root.service\r\nrm /etc/systemd/system/garageqtpi@root.service\r\n```\r\n\r\nThe following is the updated script\r\n\r\n```\r\n#!/bin/bash\r\ncp garageqtpi@pi.service /etc/systemd/system/garageqtpi@${SUDO_USER:-${USER}}.service\r\nsed -i \"s?/home/pi/GarageQTPi?`pwd`?\" /etc/systemd/system/garageqtpi@${SUDO_USER:-${USER}}.service\r\nsystemctl --system daemon-reload\r\nsystemctl enable garageqtpi@${SUDO_USER:-${USER}}.service\r\n```"}}
{"actor":{"display_login":"tagno25"}}