How to run a python program as soon as power is turned on Jetson nano jetpack

I want to run a python code which in turn runs a object detection program on jetson nano but I want the script to run as soon as power is turned on. (there shouldn’t be a need login through headless mode)…
Can anyone help out and give me the correct method?

EDIT: To be more clear of my question, instead of boot, its “turning on power”.

I have been able to do this by creating an rc.local file in /etc. I have read that there are additional steps needed to enable it, but in my case it didn’t seem to be necessary. This is what I have in mine (the & at the end allows the python script to run indefinitely:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.

python3 /home/jetson/ &

exit 0

ohh okay…I will try this out…but I dont need to run the python program indefinitely as that program will execute command that will lead to the appropriate directory (using os.chdir() ) and then run the main python program (using os.system() ) and it the main program wont stop without giving the exit command

So in that case…

I’m not putting & at the end…
Thanks for your help…

Also, I heard contrab is a much easier and it works for raspi easily…will it help me here?

You can use “Startup Applications Preferences”. Search the name of it on your Jetson Nano and write the path of your python code like visual below.

1 Like

hello @ozguryildiz , thanks for your response…Can you suggest me a solution in terminal commands as I’m using jetson in headless mode…that would be helpful

Create file ~/.config/autostart/myscript.desktop with

[Desktop Entry]
Exec=python /your/path/

1 Like

okay will do that…
But I want to confirm this thing…When I turn on the jetson…would there be a need to login in ssh (and then automatically my program will run) or it will work as soon as I login?

If there is a need to login…how do I tackle that?


It should work after system boot.