I am trying to run a python script after the start-up of a raspberry pi:
import cec
import sys
import time
import configparser
from tuya.devices import TuyaSmartSwitch
...
If I run the command manually /usr/bin/python3.7 /home/pi/subwoofer_switch/subwoofer_control.py
it works fine and has no issues.
But if I put this in a service script sudo systemctl --force --full edit subwoofer.service
:
[Unit]
Description=My script to control suboowfer smart switch
After=multi-user.target
[Service]
ExecStart=/usr/bin/python3.7 /home/pi/subwoofer_switch/subwoofer_control.py
[Install]
WantedBy=multi-user.target
I get the following output after checking the status sudo systemctl status subwoofer.service
:
● subwoofer.service - My script to control suboowfer smart switch
Loaded: loaded (/etc/systemd/system/subwoofer.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2020-06-07 13:59:34 BST; 5min ago
Main PID: 6261 (code=exited, status=1/FAILURE)
Jun 07 13:59:34 raspberrypi systemd[1]: Started My script to control suboowfer smart switch.
Jun 07 13:59:34 raspberrypi python3[6261]: Traceback (most recent call last):
Jun 07 13:59:34 raspberrypi python3[6261]: File "/home/pi/subwoofer_switch/subwoofer_control.py", line 1, in <module>
Jun 07 13:59:34 raspberrypi python3[6261]: import cec
Jun 07 13:59:34 raspberrypi python3[6261]: ModuleNotFoundError: No module named 'cec'
Jun 07 13:59:34 raspberrypi systemd[1]: subwoofer.service: Main process exited, code=exited, status=1/FAILURE
Jun 07 13:59:34 raspberrypi systemd[1]: subwoofer.service: Failed with result 'exit-code'.
I did check that cec library is installed python3 -m pip install cec
:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: cec in /home/pi/.local/lib/python3.7/site-packages (0.2.7)
I don't quite understand what's going wrong.