how do i call a python script from crontab that requires using activate (source env/bin/active)?
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 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:
#!/home/user/virtualenv/bin/python
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/cronjob
and your virtualenv's Python interpreter is at ~/virtualenv/python
, you could put this in your crontab:
* * * * * /home/virtualenv/python /home/bin/crontab