how do i call a python script from crontab that requires using activate (source env/bin/active)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Virtualenv’s activate script is pretty simple. It mostly sets the path to your virtualenv’s Python interpreter; the other stuff that it does (setting
PS1, saving old variables, etc.) aren’t really necessary if you’re not in an interactive shell. So the easiest way is just to launch your Python script with the correct Python interpreter, which can be done in one of two ways:1. Set up your Python script to use your virtualenv’s Python interpreter
Assuming your virtualenv’s interpreter is at
~/virtualenv/bin/python, you can put that path at the top of your Python script:And then launch your script from your crontab, as normal.
2. Launch the script with the proper Python interpreter in your cronjob
Assuming your script is at
~/bin/cronjoband your virtualenv’s Python interpreter is at~/virtualenv/python, you could put this in your crontab: