Notifications
Clear all

Auto start a python script on boot  


SuperCharlie
(@supercharlie)
Trusted Member
Joined: 1 month ago
Posts: 90
Topic starter  

Anybody have a quick easy way to make a python script automatically run on boot? I've done a little bit of googling and it's not pretty.

Anyone got this going on?


Quote
KUTGV
(@kutgv)
Active Member
Joined: 11 months ago
Posts: 5
 

I think that this will work but use the text editor in the GUI or nano in the CLI to make the service file, vi is rather old school.

 

https://tecadmin.net/setup-autorun-python-script-using-systemd/

 

Mario


ReplyQuote
jfabernathy
(@jfabernathy)
Estimable Member
Joined: 2 months ago
Posts: 123
 

What to pick as a method depends on how you boot your RPI. Do you have it boot into the Desktop? or do you set it to login first? or console automatic login?

Here is a link to 5 ways to do it. run-a-program-on-your-raspberry-pi-at-startup

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


ReplyQuote
SuperCharlie
(@supercharlie)
Trusted Member
Joined: 1 month ago
Posts: 90
Topic starter  

Thank you both for the suggestions. I will look at both today and report back.


ReplyQuote
SuperCharlie
(@supercharlie)
Trusted Member
Joined: 1 month ago
Posts: 90
Topic starter  

Well.. even though my script runs just fine once I'm logged in I tried just about every one of those Autostarts and it looks like the sound parts aren't loading on boot. Part of the script has pyaudio sound module and best I can tell at the moment it's not initialized so the card slot isn't available.. at least that's my guess at the moment. I'm going to regroup and give it another try tomorrow probably...


ReplyQuote
SuperCharlie
(@supercharlie)
Trusted Member
Joined: 1 month ago
Posts: 90
Topic starter  

Okay I wanted to report back that this has been solved. 

The issue was that one of the sound modules I needed was not capable of running as sudo. each of the various ways to launch an application on boot stops before the user logs in.. so in the end I found this which worked since I needed a terminal anyways.

To note, once you do that process all you get is a terminal window you can stop the application but you don't get desktop or regular command prompt until you undo these things as well.

https://blog.startingelectronics.com/auto-start-a-desktop-application-on-the-rapberry-pi/


ReplyQuote