简体   繁体   English

使用 Python 虚拟环境创建 Crontab

[英]Creating Crontab with Python virtual environment

I need to set a Crontab for every fives minutes to run a Python script that's in a virtual environment.我需要每五分钟设置一个 Crontab 来运行虚拟环境中的 Python 脚本。 What I tried so far doesn't seem to be launching.到目前为止,我尝试的似乎还没有启动。

In addition.此外。 in the cron command I have it activating the virtual environment, but that seems incorrect because I should have to open a virtual environment every five minutes.在 cron 命令中,我让它激活了虚拟环境,但这似乎不正确,因为我应该每五分钟打开一个虚拟环境。 I'm not sure what the proper way of doing this is.我不确定这样做的正确方法是什么。

*/5 * * * *  source /home/robothead/scripts/python/venvs/kraken/bin/activate && python3 /home/robothead/scripts/python/kraken/kquest3.py

You could try to use the absolute path for the python3 interpreter.您可以尝试使用 python3 解释器的绝对路径。 Basically, I meant to try:基本上,我打算尝试:

*/5 * * * *  source /home/robothead/scripts/python/venvs/kraken/bin/activate && /home/robothead/scripts/python/venvs/kraken/bin/python3 /home/robothead/scripts/python/kraken/kquest3.py

If that does not help, I would suggest running kquest3.py in VSCode and see the command that the terminal runs.如果这没有帮助,我建议在 VSCode 中运行 kquest3.py 并查看终端运行的命令。 You could then execute that same command in crontab.然后,您可以在 crontab 中执行相同的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM