How to automatically run a python script when you turn on your Raspberry Pi

How to automatically run a python script when you turn on your Raspberry Pi

When you've made a python script to handle control inputs, outputs and other elements for your RNBO patchers running on the Raspberry Pi - you'll likely want to start it running every time you boot, without having to initiate it in the terminal.

Cron

Cron is a unix utility for scheduling processes. You can schedule jobs to run at designated times - once or repeatedly.

crontab -e 

crontab is the table which schedules the jobs that the cron daemon will run. We pass the e flag for editing.

If prompted for an editor, use nano if unsure.

You will see some comments in the file which indicate how to use it, with manpage numbers for crontab and cron.

To create an entry that will run a python script on reboot. Provide a full path (not a relative path). Note the ampersand character at the end.

@reboot python /home/pi/path/to/myScript.py &

ctrl + O will write out the file. then sudo reboot to test out the changes.

lys.//

lys.//

I'm an audio programmer, data scientist, grad researcher and media artist from Melbourne, Australia. I specialise in DSP and interactive coding for sound design across a wide array of platforms.
Australia