简体   繁体   中英

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. 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. 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. 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. You could then execute that same command in crontab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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