问题
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.
Run a python script in virtual environment from windows task scheduler
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
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.
回答1:
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
goes into task.bat file.
In task scheduler, run task.bat
from cmd.
来源:https://stackoverflow.com/questions/57397693/how-to-schedule-a-python-script-to-run-from-virtual-environment-via-task-schedul