Run a python script in virtual environment from windows task scheduler

后端 未结 5 1707
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 20:48

I\'m trying to set up a recurring Python task through windows task scheduler.

I have had success when I input the path to \'python.exe\' and provide the script\'s pa

5条回答
  •  無奈伤痛
    2020-12-03 21:44

    Though the answer by mx0 above seems to work, I have set up Task Scheduler to run a flask web app on bootup. In this case, manual starting works fine, but manual ending does not. Ending the task kills the cmd.exe task that sets up the virtual environment, but the python.exe continues to run.

    The solution that I found worked was from this reddit post which skips the virtual environment activation to call the python executable directly:

    path\to\venv\Scripts\python.exe path\to\script.py
    

    I'm not sure how robust this will be, but at least this way ending the task will end the python.exe

提交回复
热议问题