I had the same problem - built a model that works fine, exported to python script which ran fine - but could not seem to get it to run as scheduled task and pulled my hair out for two days before I got it to work on my machine. There were many posts offering various solutions and I tried all of them to no avail. I tried running the script through a batch file, I tried changing the "start in" location, I tried running cmd as the program with various options in the arguments list. I guess all of these things were worth trying as they did seem to solve the problem for some people, but not others - namely me!
This finally worked for me (in addition to a fifth of whiskey):
I used this snippet to be sure I had the correct path to python.exe, as there are several instances of the file on my machine:
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")
I created a basic task with task scheduler.
Then under the "task actions" tab, I used the following:
Program/Script:
My full path to python.exe:
C:\Python27\ArcGIS10.3\python.exe
Add Arguments:
The full path to my script - in my case:
C:\Users\wwbill22\Documents\ArcGIS\PyScripts\runModel.py
(note that you will need to enclose in double quotes if your path contains spaces).
Finally, my task runs as scheduled.
I should note that under general task properties I have NOT checked "Run with Highest Privileges" NOR have I selected "Run whether user is logged on or not"
If I try to use either of those options I get the familiar 0x1 error. Which is unfortunate, but I can live with leaving the user logged on.
I also found out as I researched this issue that I did not have to export the model to a python script to schedule it as a task. Since my model was saved in a toolbox, I could simply write a script to import the toolbox and call the model directly. This has the added value of not having to update my script if I decide to edit my model tool in the future. Didn't have a bearing on my task scheduler issue but I thought it was interesting nonetheless.
Here is the script I used to achieve that:
import arcpy
# Import custom toolbox
arcpy.ImportToolbox("L:/GIS/Toolboxes/Collin_Tools.tbx")
try:
# Run tool in the custom toolbox. The tool is identified by
# the tool name and the toolbox alias.
arcpy.Model3_collintools()
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
Hope this helps someone else out!