How to set virtualenv for a crontab?

Continuation picture Continuation · Nov 11, 2010 · Viewed 42.7k times · Source

I want to set up a crontab to run a Python script.

Say the script is something like:

#!/usr/bin/python
print "hello world"

Is there a way I could specify a virtualenv for that Python script to run in? In shell I'd just do:

~$ workon myenv

Is there something equivalent I could do in crontab to activate a virtualenv?

Answer

Mike Pennington picture Mike Pennington · Oct 11, 2012

Another solution that works well for me...

0    9    *    *    *    /path/to/virtenv/bin/python /path/to/cron_script.py

I prefer using python directly from the virtualenv...