Fuente: https://www.jcchouinard.com/python-automation-using-task-scheduler/
This post will show you how to schedule a Python Script execution using Windows Task Scheduler. This will help you automate tasks using Python on Windows.
Use crontab for python script automation on Mac.
With python scripts, you could extract data from Google Search Console and Google Analytics every day and send yourself a weekly email report. You could log all your keywords every day or automate your keywords research.
Before we can cover all that, we need to learn how to use Windows Task Scheduler.
What is Windows Task Scheduler?
Windows Task Scheduler is a component that gives the ability to schedule and automate tasks in Windows by running scripts or programs automatically at a given moment.
Get Started Using Windows Task Scheduler
To run your python scheduler you will need to create a task, create an action, add the path to your python executable file and to you python script and add a trigger to schedule your script.
1. Create Your First Task
Search for “Task Scheduler”.
This will open the Windows Task Scheduler GUI.
Go to Actions > Create Task…
Give a name
2. Create an Action
Go to Actions > New
3. Add the Python Executable File to the Program Script
Find the Python Path using where python
in the command line.
From the command prompt copy the script to use in the action.
C:\yourpath\python.exe
or in my case
C:\Users\j-c.chouinard\AppData\Local\Continuum\anaconda3\python.exe
In Program/Script, add the path that you have copied from the command line.
4. Add the Path to Your Python Script in the Arguments
Go to the folder where your Python script is located. Right-click on the file and select Copy as path
.
If you have a file located at this location.
C:\user\your_python_project_path\yourFile.py
In the "Add arguments (optional)
” box, you will add the name of your python file.
yourFile.py
In the "Start in (optional)"
box, you will add the location of your python file.
C:\user\your_python_project_path
Click “OK”.
Note: Alternatively, you could create a batch file combining your Python script and Python executable file in a
.bat
file.
5. Trigger Your Script Execution
Go to “Triggers” > New
Choose the repetition that you want. Here you can schedule python scripts to run daily, weekly, monthly or just one time.
Click “OK”
Once, you have set this up, your trigger is now active and your python script will run automatically every day.
Task Scheduler Python Script Automation FAQs
📙Can Task Scheduler run a Python script?
🐍How to schedule a Python script with Task Scheduler?
⭐Does Task Scheduler work when computer is sleeping?
That’s it, you now know how to run a Python script automatically using Windows Task Scheduler.