Notifications
Clear all

Auto start a python script on boot

6 Posts
3 Users
2 Likes
820 Views
SuperCharlie
(@supercharlie)
Member
Joined: 3 years ago
Posts: 81
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)
Member
Joined: 4 years ago
Posts: 10
 

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


   
SuperCharlie reacted
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
 

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.


   
SuperCharlie reacted
ReplyQuote
SuperCharlie
(@supercharlie)
Member
Joined: 3 years ago
Posts: 81
Topic starter  

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


   
ReplyQuote
SuperCharlie
(@supercharlie)
Member
Joined: 3 years ago
Posts: 81
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)
Member
Joined: 3 years ago
Posts: 81
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