在Windows 10中调度任务调度程序上的.py文件

时间:2021-08-19 05:06:11

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

我已经尝试将.py文件转换为.exe文件。不幸的是,.exe文件存在问题;我认为这是因为我的代码相当复杂。所以,我正在尝试用任务调度程序直接调度我的。py文件,但是每次我做它,然后运行它,看看是否有效,一个窗口弹出,问我想如何打开程序

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

你们中有人知道我如何用任务调度程序成功地调度我的。py文件吗?请帮助,谢谢

Windows 10 Python 3.5.2

Windows 10 Python 3.5.2

3 个解决方案

#1


7  

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.Launch Window’s Task Scheduler 2.Look for the The Actions pane(on the right) it has the Create Basic Task action. Click on it. 3.This will open a wizard where you will define the name of your task, the trigger (when it runs), and the action (what program to run). Action tab is where you specify the name of your Python script to run as well as any arguments to the script.

创建exe应该是最好的方法。但是如果你想用任务调度程序运行它,你可以这样做:1。启动窗口的任务调度程序2。查找操作窗格(在右边),它有创建基本任务操作。点击它。3所示。这将打开一个向导,在那里您将定义任务的名称、触发器(运行时)和操作(运行什么程序)。Action选项卡指定要运行的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.

确保您的Python脚本将运行无论登录账户,调度任务使用,并避免任何混淆使用哪个版本的Python在混合环境中(64位或32位),建议您运行Python可执行您的Python文件的名称作为参数的可执行文件。

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:

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

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

C:\ Python27 \ ArcGIS10.2 \ python。exe“E:\我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.

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

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: 在Windows 10中调度任务调度程序上的.py文件

在确定python的位置之后。exe,这是在任务调度程序的操作面板中输入的内容:

If there are additional arguments (parameters) to your script, provide them after the path to your script. Hope this helps.

如果脚本中有其他参数(参数),请在脚本的路径之后提供它们。希望这个有帮助。

#2


6  

You should set in the Action tab:

您应该在Action选项卡中设置:

  • in programs, the path to your python.exe: for instance C:\Users\Me\AppData\Local\Programs\Python\Python36\python.exe
  • 在程序中,到python的路径。exe:例如C:\Users\Me\AppData\Local\Programs\Python\Python36\python.exe
  • in arguments, the filename with the extension: for instance mypythonsrcipt.py
  • 在参数中,带有扩展名的文件名:例如mypythonsrcipt.py
  • in start in, the folder of your script: for instance C:\Users\Me\Desktop\
  • 在开始,你的脚本的文件夹:例如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)

同样,每次修改任务时,General选项卡中的用户帐户将切换到中等强制级别。因此,我必须重新打开taks,并将用户帐户设置为我的用户名:(cf. this question)

在Windows 10中调度任务调度程序上的.py文件

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.

如果您仍然不能运行脚本,请进入事件日志、应用程序和服务日志/Microsoft/Windows/TaskScheduler/Operational(右键单击它以启用它)并查找错误。

#3


0  

The script you execute would be the exe found in your python directory ex) C:\Python27\python.exe

执行的脚本将是在python目录ex中找到的exe) C:\Python27\python.exe

The "argument" would be the path to your script ex) C:\Path\To\Script.py

“参数”将是您的脚本ex) C:\路径到\Script.py的路径

So think of it like this: you aren't executing your script technically as a scheduled task. You are executing the root python exe for your computer with your script being fed as a parameter.

因此可以这样想:从技术上讲,您并不是按照预定的任务执行脚本。您正在为您的计算机执行根python exe,并将脚本作为参数提供。

#1


7  

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.Launch Window’s Task Scheduler 2.Look for the The Actions pane(on the right) it has the Create Basic Task action. Click on it. 3.This will open a wizard where you will define the name of your task, the trigger (when it runs), and the action (what program to run). Action tab is where you specify the name of your Python script to run as well as any arguments to the script.

创建exe应该是最好的方法。但是如果你想用任务调度程序运行它,你可以这样做:1。启动窗口的任务调度程序2。查找操作窗格(在右边),它有创建基本任务操作。点击它。3所示。这将打开一个向导,在那里您将定义任务的名称、触发器(运行时)和操作(运行什么程序)。Action选项卡指定要运行的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.

确保您的Python脚本将运行无论登录账户,调度任务使用,并避免任何混淆使用哪个版本的Python在混合环境中(64位或32位),建议您运行Python可执行您的Python文件的名称作为参数的可执行文件。

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:

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

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

C:\ Python27 \ ArcGIS10.2 \ python。exe“E:\我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.

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

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: 在Windows 10中调度任务调度程序上的.py文件

在确定python的位置之后。exe,这是在任务调度程序的操作面板中输入的内容:

If there are additional arguments (parameters) to your script, provide them after the path to your script. Hope this helps.

如果脚本中有其他参数(参数),请在脚本的路径之后提供它们。希望这个有帮助。

#2


6  

You should set in the Action tab:

您应该在Action选项卡中设置:

  • in programs, the path to your python.exe: for instance C:\Users\Me\AppData\Local\Programs\Python\Python36\python.exe
  • 在程序中,到python的路径。exe:例如C:\Users\Me\AppData\Local\Programs\Python\Python36\python.exe
  • in arguments, the filename with the extension: for instance mypythonsrcipt.py
  • 在参数中,带有扩展名的文件名:例如mypythonsrcipt.py
  • in start in, the folder of your script: for instance C:\Users\Me\Desktop\
  • 在开始,你的脚本的文件夹:例如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)

同样,每次修改任务时,General选项卡中的用户帐户将切换到中等强制级别。因此,我必须重新打开taks,并将用户帐户设置为我的用户名:(cf. this question)

在Windows 10中调度任务调度程序上的.py文件

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.

如果您仍然不能运行脚本,请进入事件日志、应用程序和服务日志/Microsoft/Windows/TaskScheduler/Operational(右键单击它以启用它)并查找错误。

#3


0  

The script you execute would be the exe found in your python directory ex) C:\Python27\python.exe

执行的脚本将是在python目录ex中找到的exe) C:\Python27\python.exe

The "argument" would be the path to your script ex) C:\Path\To\Script.py

“参数”将是您的脚本ex) C:\路径到\Script.py的路径

So think of it like this: you aren't executing your script technically as a scheduled task. You are executing the root python exe for your computer with your script being fed as a parameter.

因此可以这样想:从技术上讲,您并不是按照预定的任务执行脚本。您正在为您的计算机执行根python exe,并将脚本作为参数提供。