- 1 year ago
Running a python script from startup. (Windows and RPI os)
To run a Python script at startup on Windows or Raspberry Pi OS, you can use the following steps:
On Windows:
Open the Run dialog by pressing the
Win
+R
keys.Type
shell:startup
and pressEnter
. This will open the Startup folder.Create a shortcut to your Python script by right-clicking in the Startup folder, selecting "New," and then "Shortcut."
In the "Create Shortcut" dialog box, type
python path\to\your\script.py
in the "Type the location of the item" field, wherepath\to\your\script.py
is the path to your Python script. Click "Next."Enter a name for the shortcut, and click "Finish."
Restart your computer to see if the Python script runs at startup.
On Raspberry Pi OS:
Open a terminal window.
Type
sudo nano /etc/rc.local
to open therc.local
file.Add the following line to the file, before the
exit 0
line:bashpython path/to/your/script.py &
Replace
path/to/your/script.py
with the path to your Python script.Save and close the
rc.local
file.Restart your Raspberry Pi to see if the Python script runs at startup.
Note that on Raspberry Pi OS, you may need to add execute permissions to your Python script by running the command chmod +x path/to/your/script.py
before it can be run at startup.