I already tried to convert my .py file into .exe file. Unfortunately, the .exe file gives problems; I believe this is because my code is fairly complicated. So, I am trying to schedule directly my .py file with Task Scheduler but every time I do it and then run it to see if works, a window pops up and asks me how I would like to open the program?-.-
Does any of you know how I can successfully schedule my .py file with Task Scheduler? Please help, thanks
Windows 10 Python 3.5.2
One good approach is to schedule these scripts as per your need; daily at 5 PM or weekly once on Sunday 12 AM etc. There are a number tools available at your disposal such as — schedule, apscheduler, python-crontab, apache-airflow, etc. that you can use to schedule your Python jobs .
Automate Python Script Using Windows Task Scheduler Give your task a name. Go to the “Tiggers” tab, change the settings to Daily, and make sure recur every 1 day since we want the bot to run every day. Also, make sure the Start time is in the past, otherwise, it won't run until that time comes.
Creating the exe should be the best method. But if you want to run it with the task scheduler you can do it in this way:
To ensure that your Python script will run regardless of the login account that the schedule task uses, and to avoid any confusion about which version of Python is used in mixed environments (64bit or 32bit), it is recommended that you run the Python executable with the name of your Python file as an argument to the executable.
Suppose the script you want to run is E:\My script.py. Instead of running the script directly, instruct the task scheduler to run python.exe with the script as an argument. For example:
C:\Python27\ArcGIS10.2\python.exe "E:\My script.py"
The location of python.exe depends on your install. If you don’t know where it is, you can discover its location; copy and paste the following code into a new Python script then execute the script. The script will print the location of python.exe as well as other information about your Python environment.
import sys
import platform
import imp
print("Python EXE : " + sys.executable)
print("Architecture : " + platform.architecture()[0])
print("Path to arcpy : " + imp.find_module("arcpy")[1])
raw_input("\n\nPress ENTER to quit")
After determining the location of python.exe, this is what is entered in the Action panel of the task scheduler:
If there are additional arguments (parameters) to your script, provide them after the path to your script. Hope this helps.
You should set in the Action
tab:
"C:\Users\Me\AppData\Local\Programs\Python\Python36\python.exe"
"C:\Users\Me\Desktop\mypythonsrcipt.py"
If this doesn't work, try :
"C:\Users\Me\AppData\Local\Programs\Python\Python36\python.exe"
"mypythonsrcipt.py"
"C:\Users\Me\Desktop\"
Also each time I modify a task, the user account in the General
tab is switched to Medium Mandatory Level. So I have to reopen the taks and set the user account back to my username: (cf. this question)
If you still can't run your script, go in Event Log, Applications and Service Log/Microsoft/Windows/TaskScheduler/Operational
(right click it to enable it) and look for the errors.
Dragon's answer works fine as long as your script not takes much time to finish.
I used a little different approach in the Windows task scheduler:
In Program/script
textbox you set the path to Python executable (in my case is inside the virtualenv folder).
Add arguments
= Just the name of your Python script.
Start in
= The full path of your Python script (without the name.py).
This way the script runs, the console stays open and waits until the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With