0

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.

  • Virtual environments don't have to be activated. Directly run the fully-qualified path to "python.exe" in the environment. There's no need for a batch script. – Eryk Sun Aug 07 '19 at 20:04

1 Answers1

0

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.

Pavan Tej
  • 71
  • 5
  • I tried this, which was a step in the right direction, but I believe there are still errors in the code snippet above. For example, there might be an issue in `activate.bat && python` - I'm not sure what `.bat` does in the context of a batch file. Likewise, I would think that python still requires a full path, vice just calling `python`. –  Aug 07 '19 at 19:05
  • activate.bat would activate your python virtual environment. As per `python`, make sure you have python path added in your environment variables. Nevertheless, do you mind commenting what error you got after following this approach ? – Pavan Tej Aug 07 '19 at 19:14