Kraggy123
Posts: 34
Joined: Wed Feb 28, 2018 5:50 pm

Running a Python script on startup

Sat Mar 03, 2018 8:35 pm

Hi, I recently bought a raspberry Pi and for my current project I want a python script to run on startup. I have looked online but anything I've tried I either don't understand or hasn't worked.

If anyone has a straightforward way of having a python script run on startup, I would greatly appreciate your help.

User avatar
DougieLawson
Posts: 34920
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Running a Python script on startup

Sat Mar 03, 2018 9:39 pm

Add a line in /etc/rc.local.
Add a @reboot line in crontab -e.
Add a line in the LXDE autostart
Add a line in ~/.profile (although that may get multiple copies running)

Pick your poison.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

klricks
Posts: 6235
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Running a Python script on startup

Sat Mar 03, 2018 11:36 pm

If you boot to desktop then it is easy to use autostart

Code: Select all

nano /home/pi/.config/lxsession/LXDE-pi/autostart
Add an entry to the end like this:

Code: Select all

@lxterminal -e python /path_to_your_file/your_file.py
(For python 3 use python3)
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

Kraggy123
Posts: 34
Joined: Wed Feb 28, 2018 5:50 pm

Re: Running a Python script on startup

Sun Mar 04, 2018 5:05 pm

Ah ok, thank you very much I'll give them a go.

Return to “Beginners”