Answer the question
In order to leave comments, you need to log in
How to run cron tasks from python virtual env?
Hello, there are a lot of examples on the net and, as usual, they are not working.
The cron task does not work
. What I did:
1. Determined the path to the virtual environment echo $VIRTUAL_ENV
/opt/Python-3.8.7/proj
2. Added to crontab to run once a minute
* /1 * * * * /opt/Python-3.8.7/proj [path where the script is in fact->]/opt/run_base.py
Nothing happens. Why?
Thanks
Answer the question
In order to leave comments, you need to log in
shell_guy , it is better to specify full paths to all files.
This is how it works for me, anyway.
cd /opt/my_python_project && sudo -u username /opt/my_python_project/bin/python3 /opt/my_python_project/main.py
I did this: cd python/project && source venv/bin/activate && python3 main.py
Well, probably because, firstly, that the path needs to be continued - something like:
/opt/Python-3.8.7/proj/bin/python
to the binary that your script will run
Secondly, take into account that your environment and the crontab environment are different ..
You may need to register some paths and so on .. .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question