sudo nano /etc/rc.local
- Add your lines before the exit 0
- You may need to cd to the directory first (it won’t hurt to have this, but isn’t strictly required)
- If your script runs in the background, put an ampersand, ‘&’ at the end of the line calling your executable, or you will not be able to get control of your pi easily
- If your script terminates, you don’t have to use the ‘&’
cd /home/pi/mysubdirectory python3 /home/pi/mysubdirectory/myexecutable.py &
Reboot, then run ps aux | grep myexecutable.py to see if it worked (see Kill a Process for details).
If it doesn’t work:
- Be sure you put your lines BEFORE exit 0
- Execute the same line from your command line. Chances are your program has a bug which you will see in the terminal window.
- Did you reboot?