If you plan to make a python script be started at specified time every day in windows, the best solution is to use task scheduler. In this tutorial, we will tell you how to create a scheduled task to run a python script.
Create a python script you plan to run at specified time every day
As a test, we have created a python script, which is named to task_scheduler_test.py
The code in this file is:
import time print("hello") time.sleep(15)
The absolute path of this python script is: E:\workspace-nlp\Example\task_scheduler_test.py
Check the absolute path of your python.exe
To run python script in windows 10, you should know the absolute path of python.exe. As to us, the path of python.exe is: C:\Users\fly165\.conda\envs\py3.6\python.exe
Open window 10 command window
You can press win + R to open command window and enter compmgmt.msc.
Then you can open windows computer management to create a scheldued task.
Create a basic task
You can start to create a basic scheldued task like below:
Input task name and task description
In this tutorial, we will use name: Python Task Scheduler Test. You can modify it to your own.
Select to run this task daily
You can do this like this.
Set time when runs task
You can choose a time to run python script daily.
Then start to run an application
Set python.exe path adn python script for this task
You should add the absolute path of python.exe and task_scheduler_test.py as this:
Then click finish button.
You will find Python Task Scheduler Test has been add to windows task scheduler successfully.