在 Windows 10 中的 Task Scheduler 上安排 .py 文件 [英] Scheduling a .py file on Task Scheduler in Windows 10

查看:42
本文介绍了在 Windows 10 中的 Task Scheduler 上安排 .py 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试将我的 .py 文件转换为 .exe 文件.不幸的是,.exe 文件有问题;我相信这是因为我的代码相当复杂.所以,我试图用 Task Scheduler 直接安排我的 .py 文件,但每次我这样做然后运行它以查看是否有效时,会弹出一个窗口并询问我想如何打开该程序?-.-

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?-.-

你们中有人知道如何使用 Task Scheduler 成功安排我的 .py 文件吗?请帮忙,谢谢

Does any of you know how I can successfully schedule my .py file with Task Scheduler? Please help, thanks

Windows 10Python 3.5.2

Windows 10 Python 3.5.2

推荐答案

创建 exe 应该是最好的方法.但是如果你想用任务调度器运行它,你可以这样做:

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:

  1. 启动窗口的任务计划程序
  2. 寻找具有创建基本任务操作的操作窗格(在右侧).点击它.
  3. 这将打开一个向导,您将在其中定义任务的名称、触发器(运行时)和操作(要运行的程序).操作选项卡用于指定要运行的 Python 脚本的名称以及脚本的任何参数.

为了确保您的 Python 脚本无论计划任务使用的登录帐户如何都能运行,并避免混淆在混合环境(64 位或 32 位)中使用的 Python 版本,建议您运行Python 可执行文件,将 Python 文件的名称作为可执行文件的参数.

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.

假设您要运行的脚本是 E:\My script.py.不是直接运行脚本,而是指示任务调度程序以脚本作为参数运行 python.exe. 例如:

C:\Python27\ArcGIS10.2\python.exe "E:\My script.py"

C:\Python27\ArcGIS10.2\python.exe "E:\My script.py"

python.exe 的位置取决于您的安装.如果你不知道它在哪里,你可以发现它的位置;将以下代码复制并粘贴到新的 Python 脚本中,然后执行该脚本.该脚本将打印 python.exe 的位置以及有关 Python 环境的其他信息.

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")

确定python.exe的位置后,在任务调度器的Action面板中输入的是这样的:

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.

这篇关于在 Windows 10 中的 Task Scheduler 上安排 .py 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆