Python 3.9.2
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
I installed a package (pycomm3) with pip because it isn't available with apt.
If I start the python program from the command line, it works fine. If I try to have it autostart with systemd, pycomm3 is not found.
Command line:
python3 /home/pi/Documents/pyprog.py
Service:
Description=Start Exit Data
After=network.target
[Service]
Environment=Display=:0
Environment=XAUTHORITY/home/pi/.Xauthority
ExecStart=python3 /home/pi/Documents/pyprog.py
Restart=always
RestartSec=5s
KillMode=process
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target
Error from systemctl status ExitData.service:
Loaded: loaded (/lib/systemd/system/ExitData.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024年07月02日 08:50:20 EDT; 222ms ago
Main PID: 2254 (python3)
Tasks: 1 (limit: 8754)
CPU: 210ms
CGroup: /system.slice/ExitData.service
└─2254 python3 /home/pi/Documents/pyprog.py
Jul 02 08:50:20 pi systemd[1]: Started ExitData.service.
Jul 02 08:50:20 pi python3[2254]: Traceback (most recent call last):
Jul 02 08:50:20 pi python3[2254]: File "/home/pi/Documents/pyprog.py", line 14, in <module>
Jul 02 08:50:20 pi python3[2254]: from pycomm3 import LogixDriver
Jul 02 08:50:20 pi python3[2254]: ModuleNotFoundError: No module named 'pycomm3'
Jul 02 08:50:20 pi systemd[1]: /lib/systemd/system/ExitData.service:1: Assignment outside of section. Ignoring.
Jul 02 08:50:20 pi systemd[1]: /lib/systemd/system/ExitData.service:2: Assignment outside of section. Ignoring.
Jul 02 08:50:20 pi systemd[1]: /lib/systemd/system/ExitData.service:3: Assignment outside of section. Ignoring.
Jul 02 08:50:20 pi systemd[1]: ExitData.service: Main process exited, code=exited, status=1/FAILURE
Jul 02 08:50:20 pi systemd[1]: ExitData.service: Failed with result 'exit-code'.
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.Community– Community Bot2024年07月04日 07:25:03 +00:00Commented Jul 4, 2024 at 7:25
1 Answer 1
sudo pip install pycomm3 fixed that error
-
Might be useful if you explained why that fixed the error.goldilocks– goldilocks2024年07月02日 21:54:32 +00:00Commented Jul 2, 2024 at 21:54
-
I would if I knew why.evanmars– evanmars2024年07月25日 20:12:00 +00:00Commented Jul 25, 2024 at 20:12
-
You must have gotten the idea from somewhere -- anyway it's because modules installed as a normal user are available to that user (hence, when you ran the script from the command line), but not to the system as a whole (when you run it as a systemd service). Those have to be installed by the root user (because of security concerns amongst other things).goldilocks– goldilocks2024年07月27日 13:30:10 +00:00Commented Jul 27, 2024 at 13:30
lang-py