python-3.x - 从Windows Task Scheduler在虚拟环境中运行python脚本

标签 python-3.x windows-task-scheduler python-venv

我正在尝试通过Windows Task Scheduler设置一个重复执行的Python任务。

当我输入“python.exe”的路径并将脚本的路径作为Windows Task Scheduler的参数提供时,我已经成功了(请参见下面的屏幕截图)

windows task scheduler

但是,我希望能够选择在其中运行脚本的特定虚拟环境。我对venv不太了解,通常通过打开cmd并在所需的虚拟环境目录中运行Scripts \ activate.bat来使用它。

如何使用Windows Task Scheduler完成“每24小时在venvxxx中运行任务x”?

最佳答案

使用以下命令创建批处理文件:

c:\__full_path_to_virtualenv__\Scripts\activate.bat && python __full_path_to_python_script__.py

&&表示如果command1成功完成,则运行command2。

然后将该批处理文件设置为要运行的脚本。如果脚本必须从特定目录读取/写入并使用相对路径,则无需在任务计划程序中设置任何其他参数(也可以在批处理文件中设置它们),也可以设置Start in。

关于python-3.x - 从Windows Task Scheduler在虚拟环境中运行python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34622514/

相关文章:

python-3.x - Pytest assert_has_calls 用法

python - sys.stdin.readline() 和 input() : which one is faster when reading lines of input, 为什么?

python - 在 Python 中从链表中删除头节点

windows - Windows schtasks 中 xml 文件中 ExecutionTimeLimit 的开关是什么?

python - 如何让pip将包安装到虚拟环境中?

python - Django 模块未找到错误

python - boxPoints 返回负 y 值

batch-file - Schtasks 找不到计划任务

windows - 输出未重定向到Windows任务内的文件

python - 如何使用 Python 3 venv 使用 postactivate 脚本?