如何通过任务调度程序安排python脚本从虚拟环境运行

如何通过任务调度程序安排python脚本从虚拟环境运行

问题描述:

我偶然发现了一个基本完全相同问题的答案,但要么是我实施的解决方案有误,要么解决方案不再准确,要么有其他问题在起作用.

I stumbled on an answer for basically the exact same question, but either I am implementing the solution wrong, the solution is no longer accurate, or some other issue is at play.

在虚拟环境中运行 python 脚本来自 Windows 任务调度程序

我使用了上面链接中的代码,为我的目录进行了编辑,然后直接复制到任务调度程序/脚本提示中.

I used the code from above link, edited for my directories, and copied directly into the task scheduler program/script prompt.

C:\Users\I511843\myenv\activate.bat && python C:\Users\I511843\Desktop\Atom_scripts\test.py

然后我将程序设置为每次我解锁机器时都运行.该程序只是编写一个名为 test.txt 的文本文件,其中包含文本成功!"

I then set the program to run every time I unlocked the machine. The program simply writes a text file called test.txt containing the text "success!"

当我从命令行运行时,文本文件会填充到正确的目录中,但是,该程序不会从任务调度程序中执行.

The text file populates in the correct directory when I run from the command line, however, the program doe snot execute from the task scheduler.

您是否尝试将命令放入批处理文件并从任务调度程序执行批处理文件?类似于以下内容:

Did you try putting the commands in a batch file and executing the batch file from task scheduler? Something like below:

C:\Users\I511843\myenv\activate.bat &&python C:\Users\I511843\Desktop\Atom_scripts\test.py 进入 task.bat 文件.

C:\Users\I511843\myenv\activate.bat && python C:\Users\I511843\Desktop\Atom_scripts\test.py goes into task.bat file.

在任务调度程序中,从 cmd 运行 task.bat.

In task scheduler, run task.bat from cmd.