How to make a python auto start when the Raspberry Pi boot up

I write a python under Thonny and it can run inside Thonny
Now, I want to run this python automatically when the Raspberry Pi boot up
May I know how to do this?

3 Likes

Hi Willie!

Good to have you with us.

Are you comfortable with the linux terminal?
If so, I use one approach in my Parisians Project that might work for you.

-------- FROM THE PROJECT PAGE-----------

Launching Simulation on Reboot.

We want this simulation to automatically launch when we power on the PI. There are lots of ways to do this, but I had the most success placing the following code in my .bashrc file.

sleep 5 
cd /absolute/path/to/yourproject 
python3 main.py 

Then I ensured the terminal booted on launch.

cd home/pi/.config/lxsession/LXDE-pi/ 
echo "@lxterminal" >> autostart 
reboot 

Having the terminal open appeared to be “necessary” to make the hotkeys trigger. I also found that this method ensured that wifi and other auxiliaries would be operational before the loop would run.


If you need more clarification don’t hesitate to ask :slight_smile:
Pix :heavy_heart_exclamation:

3 Likes