How in the world do I get a python script to run at startup?

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
gene0915
Level 4
Level 4
Posts: 210
Joined: Sun Oct 26, 2014 7:52 pm

How in the world do I get a python script to run at startup?

Post by gene0915 » Thu Apr 04, 2019 10:38 pm

Mint Cinnamon 19.1

So for the past four hours I've been banging my head into the wall trying to get this work and no go. I've tried everything I came across on Ubuntu forums and this forum. I have a simple python file I want to run at every boot. If I open up a terminal and go into the folder where the .py file is at and type:

Code: Select all

python3 rgb.py
.... my program works perfectly! Getting it to run at boot automatically, complete failure!

I've messed with trying to add it in that "Startup Applications" app by adding a custom command:

Code: Select all

./usr/bin/python3 /home/gene/nvdia/rgb.py

then

/usr/bin/python3 /home/gene/nvdia/rgb.py

then

./usr/bin/python3.6 /home/gene/nvdia/rgb.py

then

/usr/bin/python3.6 /home/gene/nvdia/rgb.py

then

python3 /home/gene/nvdia/rgb.py

then

./python3 /home/gene/nvdia/rgb.py
.... and it just will not work at boot time. (I'm fairly certain the commands I mentioned above are totally wrong but after the 3 hour mark, I was getting delirious with anger and was just trying anything.)

Started reading up on adding it to /etc/rc.local..... crontab..... systemd....... and zero luck. I had to walk away and ask for help on here as I'm ready to put my fist through the monitor.

Would really appreciate a helping hand. And the kicker? I set this up in Ubuntu many months ago and don't remember this being such a nightmare but I forget how I did it. Fast forward to today, I reloaded this system with Mint 19.1 and it's been an aggravating 4 hours.

dancer_69
Level 1
Level 1
Posts: 30
Joined: Thu May 19, 2011 1:25 pm

Re: How in the world do I get a python script to run at startup?

Post by dancer_69 » Thu Apr 04, 2019 10:53 pm

Check my relative thread:
viewtopic.php?f=206&t=290541
maybe something similar happens to you.

User avatar
smurphos
Level 13
Level 13
Posts: 4628
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: How in the world do I get a python script to run at startup?

Post by smurphos » Fri Apr 05, 2019 12:58 am

1) Make sure the script is executable.

2) Consider adding a shebang as the first line of your script so you don't need to explicitly call it with python3.

Code: Select all

#!/usr/bin/env python3
3) Consider storing the script in one of the standard executable path locations ~/bin or ~/.local/bin

Do all of the above and your startup command can be just

rgb.py

Depending on what your script is doing you might want it to have a short start-up delay.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

User avatar
ganamant
Level 4
Level 4
Posts: 383
Joined: Sun Mar 29, 2015 4:08 pm

Re: How in the world do I get a python script to run at startup?

Post by ganamant » Sat Apr 06, 2019 1:18 am

gene0915 wrote:
Thu Apr 04, 2019 10:38 pm
I had to walk away and ask for help on here as I'm ready to put my fist through the monitor.
Yes, walking away, and maybe sleeping over it, is the best thing. It's only a computer, after all.

Anyway, smurphos' advice looks perfectly sound. But, if for some reason it doesn't work, try writing a small helper bash script that would just invoke the python script; then, call that bash script at startup.

I don't know how complex your original script is, but try testing the calling routine with a very simple script first, maybe something that will just write a few lines of text into a temporary file, just to see if the invocation worked.

Post Reply

Return to “Newbie Questions”