How to schedule a python script to run from virtual environment via task scheduler

廉价感情. 提交于 2021-01-29 11:17:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!