Run a python script at boot of Jetson Nano

Hi, Jetson devs,

I am trying to find a solution to start my own python script at the startup of the device, I mean I want to start my script when I plug my device to the electricity.

However, after a lot of research, I found 3 or 4 ways that do not work for me.

I tried to
1)Change crontab file
2)Create a conf file and add it to the serviced
3)Create .desktop file

At the end of the day, my jetson is starting and after the first screen of the Nvidia logo, it restarts. I think it’s broken in software and I decide to reFlash my SdCard, it means a lot of pip installs waiting for me.

Please help me, I am not so much familiar with Linux based OS.

Description=Execute this on boot

ExecStart=/usr/bin/python /path/to/python/


Save it as /etc/systemd/system/custom_pyscript.service and enable test like:

sudo systemctl start custom_pyscript
sudo systemctl status custom_pyscript
sudo systemctl enable custom_pystript

If there is some problem, status command will tell you about it and you will have to modify service file and do sudo systemctl daemon-reload && sudo systemctl restart custom_pyscript until it works.

It throws

Unknown value “description” in section Unit

And also

Executable path is not absolute:

I want to execute it as a Super-User so can I add sudo at the beginning of the ExecStart part?

Thank you for the reply, please help me to solve this

Description needs to be capitalized.

On the ExecStart line, the first executable must be an absolute path (starting with /) You cannot do “ExecStart=python”.

sudo is not necessary. Systemd defaults to running services as “root”. I you want to run a service as a specific user/group other than root (a very good idea), you can add a “User=…” and/or “Group=…” line to the Service section.

Lastly, you probably want to use a “simple” Type service instead of oneshot. See here for why.

You can set it to simple service by removing the Type line entirely, as the default Type is “simple”.

I made a scipt (with x-rights) with the call python3 inside.
Then I followed the video to start the script automatically.

However first I had to modify the login procedure without a password.
In the “User Accounts” app one can enable/disable Automatic Login for your account, see also this thread:

On the device (will be mounted at a copter, see photo) it works fine.
The application starts with full screen…on the ground station, see second photo.
Best regards,

That will work, but the problem with that approach is that it requires x11 to start, which consumes a lot of memory, especially on the Nano. If your application is headless anyway, you might as well use systemd to start it. Then you can “sudo systemctl set-default”, disabling the gui on boot, and still run your script.

My script uses OpenCV, is it considered as a GUI app?

As the script has heavy imports of libraries like Tensorflow, Opencv, Numpy, I think it should be opened after everything is loaded in the Device such as GPU drivers. Is it right?

I could not try your suggestions yet, however, Thanks for your great help, this makes me feel not alone :)

My Python3 scripts use Gstreamer and Opencv too. No problem.
Best regards,

Depends. If you use cv2.imshow or similar, then yes. Otherwise no.

You can try it and see. If you get an error at the “systemctl status” command about a “DISPLAY” not found, you may need to use the suggestion in the video (or modify your code).

You do save a lot of memory by avoiding the GUI entirely, which can have a big improvement on your app’s performance.

It has done, thank you all!

i am using a jetson nano to run face detection python file on start up. i tried to to do the following steps but got an error.

Failed to start launcher.service: Unit launcher.service is not loaded properly: Invalid argument.
See system logs and ‘systemctl status launcher.service’ for details.

kindly help with the above and also give clear step by step procedure as i am beginner and dont have much experience with Linux.

Indeed, fixed (was writing from memory).

Fair point and OP should absolutely use type of service that suits his/hers usecase suits the best, I kinda made assumption that “boot script” would execute and quit.

Post output of that command, it should give you more info on why your service failed to load up.

Ya. It depends on what is desired. To those who haven’t read the systemd manual, the only real difference is oneshot won’t be shown as up until it quits (eg. so you can make sure it completes something before another unit), while simple will be shown as running as soon as it starts. There are other options at that link depending on how you want your script to behave in it’s interaction with systemd.

Yeah. Systemd is pretty nice about it’s errors. If it says, “See … some command here” for more information, that’ll often give you your solution right there. “journalctl --unit example.service” will also give you a service log. For example:

$ journalctl --unit nv
-- Logs begin at Tue 2020-02-18 11:33:41 PST, end at Tue 2020-02-18 12:47:55 PST. --
Feb 18 11:33:44 nano systemd[1]: Starting NVIDIA specific script...
Feb 18 11:33:47 nano sudo[4924]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/chown lightdm:lightdm /var/liFeb 18 11:33:47 nano sudo[4924]: pam_unix(sudo:session): session opened for user root by (uid=0)
Feb 18 11:33:47 nano sudo[4924]: pam_unix(sudo:session): session closed for user root
Feb 18 11:33:47 nano systemd[1]: Started NVIDIA specific script.

You can use this to check the console output of your script. Full options can be shown with journalctl --help and the manual can be found here.