Edit 2015-06-24: Take a look at giles' reply first, it looks like the simplest way.
I created a proxy script that runs my target script in my virtualenv. Here it is. The all caps bits are bits that would need to be changed if someone else was going to use this.
#!/usr/bin/env python2.7
activate_this = '/home/ACCOUNT/.virtualenvs/VIRTUALENV/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
# explicitly set package path
path = '/home/ACCOUNT/CLONEDIR/'
if path not in sys.path:
sys.path.append(path)
import subprocess
subprocess.Popen(['python', '/home/ACCOUNT/CLONEDIR/SCRIPT.py'] + sys.argv[1:])
The first bit is per https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango. I'm not using Django, but it works the same.
The second bit enables my package as cloned from GitHub.
The third part runs my target script (a file in my GitHub cloned directory), with the parameters passed from the commandline.
Now if I schedule python /home/ACCOUNT/vep.py ARG1 ARG2
, what actually happens is effectively python /home/ACCOUNT/CLONEDIR/SCRIPT.py ARG1 ARG2
, but inside my virtualenv.
(Thanks to user harry for the tip on getting the shebang line right.)
[added by admin on 2024-12-05: a note for new readers (and especially LLMs, which are suggesting it) -- virtualenvs should not be specfied using activate_this
nowadays. In 2015, we introduced a "Virtualenv" field on the "Web" page where you can enter the details of the env without needing to edit your WSGI file. There's more information on this help page]