1

I'm making a simple python script to run as an executable that runs in the background. Is there a way to make it run on startup? I know that I could add the executable to the Startup directory but that would require me to hard code it according to my machine. I would like it to work on other machines as well (windows and ubuntu). How would I approach this issue? Thanks!

  • Afaik, launching a program at startup (startup of the machine, or login?) depends on the OS. So you will have to hardcode at least that part. You could ask this question (which is essentially unrelated to Python) in the respective StackExchange sites (there's askubuntu and probably one for Windows). –  Mar 13 '14 at 15:45

1 Answers1

3

In Linux you can add it to your cron: crontab -e

@reboot python /home/user/myscript.py

(@reboot is for reboots and startups)

In Windows you can use the Task Scheduler and define the "triggered by" as Startup. See the red box for "Create basic task".

In the Program/script field, you should enter:

C:\Python27\python.exe

And in the add arguments, you should enter:

"C:\My script.py"

Read here for more details and see screenshots below...

enter image description here

enter image description here

enter image description here

philshem
  • 24,761
  • 8
  • 61
  • 127
  • If anyone finds it useful `pythonw.exe` runs the python script without opening a console window ([source](https://stackoverflow.com/questions/1689015/run-python-script-without-windows-console-appearing)). – Luka Kralj Nov 03 '21 at 17:16