Jump to content

Run Python Scripts on startup

Wictorian

I know how this is possible for .exe files, but are the any solutions for .py files?

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, manikyath said:

just stick a shortcut to the python script in the startup folder?

But they are set to be opened with VS Code by default. Wouldn’t it just launch VS Code?

Link to comment
Share on other sites

Link to post
Share on other sites

12 minutes ago, Wictorian said:

But they are set to be opened with VS Code by default. Wouldn’t it just launch VS Code?

Look at batch and shell scripting. 

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 3600 || GPU: RTX 3070|| Memory: 32GB @ 3200 || Cooler: Scythe Big Shuriken || PSU: 650W EVGA GM || Case: NR200P

Link to comment
Share on other sites

Link to post
Share on other sites

Did you even look at those two links I posted? 

 

 PyInstaller and pi2exe (first results in those links) are two ways you can convert your script to an executable - basically what's produced it's a small application that's a package out of python and your script and the application launches python with your script as an argument

Link to comment
Share on other sites

Link to post
Share on other sites

45 minutes ago, Wictorian said:

But they are set to be opened with VS Code by default. Wouldn’t it just launch VS Code?

you can just make the shortcut run python with that script as a launch variable.

Link to comment
Share on other sites

Link to post
Share on other sites

16 hours ago, mariushm said:

Did you even look at those two links I posted? 

 

 PyInstaller and pi2exe (first results in those links) are two ways you can convert your script to an executable - basically what's produced it's a small application that's a package out of python and your script and the application launches python with your script as an argument

I know how to make exes but I don’t want to because it overcomplicates things.

Link to comment
Share on other sites

Link to post
Share on other sites

Few ways,

 

Create a bat file and put it in the startup folder.  The bat file would look something similar to this

python3 [path to run]

Or however you run a python script on your computer in command prompt.  Confirm that it runs your python script and then put in your startup folder and it will run at login.

 

Other options, go to task scheduler.

Create a new task

Add a new trigger; selecting on startup (I can't remember you might need to click the run even if user isn't logged in...can't remember exactly when that triggers).  You could also do on login

Then under Action create a new action where the program is python and the command is the argument is the python script

3735928559 - Beware of the dead beef

Link to comment
Share on other sites

Link to post
Share on other sites

By literally putting your title into ddg here are some of the first few results that show you how to do it for:

Linux, MacOS, and, Windows.

 

adding windows to your title: "Run python scripts on startup windows": gets you even more results:

https://stackoverflow.com/questions/31130960/run-a-python-program-at-start-up-on-windows

https://copyprogramming.com/tutorial/windows-10-run-python-program-in-startup

 

 

If your question is answered, mark it so.  | It's probably just coil whine, and it is probably just fine |   LTT Movie Club!

Read the docs. If they don't exist, write them. | Professional Thread Derailer

Desktop: i7-8700K, RTX 2080, 16G 3200Mhz, EndeavourOS(host), win10 (VFIO), Fedora(VFIO)

Server: ryzen 9 5900x, GTX 970, 64G 3200Mhz, Unraid.

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 1 month later...

You can schedule anything on Windows using standard Windows Task Scheduler. On Linux, you can use systemd or crontab.

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/3/2022 at 9:06 AM, Wictorian said:

But they are set to be opened with VS Code by default. Wouldn’t it just launch VS Code?

Did you try it? 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

In WIndows:

 

1. Create a shortcut to the Python script and place it in the Startup folder

 

2. Create a batch file that runs the Python script and place it in the Startup folder

To create a batch file that runs your Python script, open a text editor and type the following command

python path/to/script.py

Save the file with a .bat extension (like "run_py_script.bat") and place it in the Startup folder

 

3. Use the Task Scheduler. create a new task and specify the script as the action to be taken

 

In Linux:

 

1. Use crontab. Run the command below to edit the jobs. You may refer to the documentation for additional information

 sudo crontab -e

 

2. (Custom) Create a startup script

 

create a new file in the /etc/init.d directory with the following contents:

#! /bin/bash
# /etc/init.d/myscript

python /path/to/script.py &

Now, make it executable with the following commands:

sudo chmod 755 /etc/init.d/myscript
sudo update-rc.d myscript defaults

 

Note that there are many other ways to do this. This is only a small amount

hey! i know to use a computer

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×