无法通过 windows 任务调度程序 运行 我的 python 脚本

Unable to run my python script through windows task scheduler

我已经安装了 anaconda 软件包,并且可以直接从控制台轻松地 运行 宁 python 笔记本和 python 脚本。我创建了一个脚本并希望它在特定时间段每天 运行 但它不起作用。所以我创建了一个简单的测试文件来检查哪里出了问题。这是我的测试文件

print("enter the no to exit")
input()

当我 运行 这个程序在命令提示符下它要求我输入然后退出。

我每天使用 windows 调度程序 https://blogs.esri.com/esri/arcgis/2013/07/30/scheduling-a-scrip/

按照本教程 运行 这个程序

我在操作选项卡中写了这个

"C:\Anaconda3\python.exe"

参数为

"E:\test.py"

而当我 运行 任务手动弹出黑色 window 并自动关闭时,我无法弄清楚是什么问题。我看到它说的是无效目录之类的东西。我不知道我做错了什么。请帮忙。

看看 this thread from stack overflow:

You can do it in the command line as follows:

schtasks /Create /SC HOURLY /TN PythonTask /TR "PATH_TO_PYTHON_EXE PATH_TO_PYTHON_SCRIPT"

That will create an hourly task called 'PythonTask'. You can replace HOURLY with DAILY, WEEKLY etc. PATH_TO_PYTHON_EXE will be something like: C:\python25\python.exe. Check out more examples by writing this in the command line:

schtasks /?

Otherwise you can open the Task Scheduler and do it through the GUI. Hope this helps.

这可能会解决您的问题。

如果仍然无法正常工作,您可以参考this thread from esri。 这将完成您的工作。

到 运行 Python 任务管理器中的程序 Windows: 在 "Programs/Script" 输入 python.exe 的路径 在 "Add Arguments" 输入脚本文件name In "Additional Information" 输入文件保存位置的路径

例如:

Python 的路径:C:\Users\your_user_name\AppData\Local\Programs\Python\Python36-32\Python.exe

脚本名称./script.py

脚本保存位置的路径:C:/文件夹名/

在.bat文件的开头添加以下命令python和python脚本的所有配置

CD /d %~dp0

在我的例子中,.bat 文件看起来像

CD /d %~dp0 
Call "C:\Python\Python37-32\python.exe" "D:\myProject\script.py" 
pause