Run a py script when my jetson starts

Hi everyone, I’m trying to run a py script when starting up my jetson but I’m getting the following error:
Dec 22 12:50:45 nvidia-desktop systemd[1]: Started My Script.
Dec 22 12:50:45 nvidia-desktop python3[3910]: Traceback (most recent call last):
Dec 22 12:50:45 nvidia-desktop python3[3910]: File “/home/pino/Desktop/ProgrammaTelai/main.py”, line 13, in
Dec 22 12:50:45 nvidia-desktop python3[3910]: from ultralytics import YOLO
Dec 22 12:50:45 nvidia-desktop python3[3910]: ModuleNotFoundError: No module named ‘ultralytics’
Dec 22 12:50:45 nvidia-desktop systemd[1]: myscript.service: Main process exited, code=exited, status=1/FAILURE
Dec 22 12:50:45 nvidia-desktop systemd[1]: myscript.service: Failed with result ‘exit-code’.

To run it I created this file:
sudo nano /etc/systemd/system/myscript.service

[Unit]
Description=My Script
After=multi-user.target

[Service]
Environment=XAUTHORITY=/home/pino/.Xauthority
Environment=DISPLAY=:0

Environment=“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/pino/.local/bin”
ExecStart=/usr/bin/python3 /home/pino/Desktop/ProgrammaTelai/main.py

[Install]
WantedBy=multi-user.target

(with the first 2 Environments added because I found them as a solution on another forum, but to be honest I don’t know what they do or if they are present in my system and the situation doesn’t change, it doesn’t work!)

and then I ran these commands:
sudo systemctl enable myscript
sudo systemctl start myscript

sudo journalctl -u myscript (for see the error)

for information, my libraries that I recall in the file have the following paths:
$ which python3
/usr/bin/python3
$ which ultralytics
/home/pino/.local/bin/ultralytics

path of the script to execute: /home/pino/Desktop/ProgrammaTelai/main.py
(main.py also calls other py files inside it which are always inside the same ProgrammaTelai folder)

I need your precious help once again!
How can I do?
Am I doing everything wrong and is there another way to run a script at system startup or do I simply need to change something?
I await your help, Thanks in advance to anyone who replies!

Hi,
There are some valid use-cases. Please refer to Jetson Nano FAQ

Q: How to autorun an app or commands at startup?

hi, I “solved” it by making a .sh file containing the instructions that I would write in the terminal and using the command $gnome-session-properties I added a new “command” with the add button which would be nothing more than the path to the file .sh

It seems like it’s working for now, are there any contraindications or suggestions to keep in mind since I’ve used this technique?

Hi,
It looks good to us. See if other users can comment. There are several methods and we are also learning from your experience. Thanks for the sharing.