How to execute a command from a virtual environment using `crontab` or `gnome-terminal`
cron, gnome-terminal, python, virtualenv, virtualenvwrapper
Solution
Through crontab:
0 10 * * * env -i bash -c 'export WORKON_HOME=~/.virtualenvs && source /usr/local/bin/virtualenvwrapper.sh && workon my_project && python task.py'
Through gnome terminal:
gnome-terminal --tab -e 'bash -c "export WORKON_HOME=~/.virtualenvs && source /usr/local/bin/virtualenvwrapper.sh && workon my_project && python task.py " '
Better of all just create a runme.sh script:
#/bin/sh
set -e
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
workon my_project
exec python task.py
And run this script through gnome terminal / crontab.
Problem
When I want to work on a virtual environment with virtualenv(1.8.2) and virtualenvwrapper(3.6) I just run `workon my_project`. I am however unable to execute a command from a virtual environment using `crontab` or `gnome-terminal`: Examples: `* * * * * workon my_project && python task.py` This is'nt executed. (The task writes to a file) or `gnome-terminal --tab -e "bash -c \"workon my_project;python task.py;exec bash\""` This just shows `bash: workon: command not found` and then executes the program from the system environment. Check here for more info about this command. Edit @Zaar Hai: To initiate `virtualenvwrapper` this in my `/home/myusername/.bashrc`: ``` export WORKON_HOME=~/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh export PIP_VIRTUALENV_BASE=$WORKON_HOME export PIP_RESPECT_VIRTUALENV=true ``` So I tried this command: ``` gnome-terminal --tab -e "bash -c \"export WORKON_HOME=~/.virtualenvs;source /usr/local/bin/virtualenvwrapper.sh;export PIP_VIRTUALENV_BASE=$WORKON_HOME;export PIP_RESPECT_VIRTUALENV=true;source /home/myusername/.virtualenvs/my_project/bin/activate;exec bash\"" ``` But I still get that same output as I posted in your comment.