0
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'.
asked Jul 2, 2024 at 13:11
1
  • 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. Commented Jul 4, 2024 at 7:25

1 Answer 1

1

sudo pip install pycomm3 fixed that error

answered Jul 2, 2024 at 13:33
3
  • Might be useful if you explained why that fixed the error. Commented Jul 2, 2024 at 21:54
  • I would if I knew why. Commented 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). Commented Jul 27, 2024 at 13:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.