virtualenvwrapper functions unavailable in shell scripts
Just source the virtualenvwrapper.sh
script in your script to import the virtualenvwrapper's functions. You should then be able to use the workon
function in your script.
And maybe better, you could create a shell script (you could name it venv-run.sh
for example) to run any Python script into a given virtualenv, and place it in /usr/bin
, /usr/local/bin
, or any directory which is in your PATH
.
Such a script could look like this:
#!/bin/sh# if virtualenvwrapper.sh is in your PATH (i.e. installed with pip)source `which virtualenvwrapper.sh`#source /path/to/virtualenvwrapper.sh # if it's not in your PATHworkon $1python $2deactivate
And could be used simply like venv-run.sh my_virtualenv /path/to/script.py
I can't find the way to trigger the commands of virtualenvwrapper
in shell. But this trick can help: assume your env. name is myenv
, then put following lines at the beginning of scripts:
ENV=myenvsource $WORKON_HOME/$ENV/bin/activate
It's a known issue. As a workaround, you can make the content of the script a function and place it in either ~/.bashrc
or ~/.profile
function run-app() { workon "$(cat .venv)" python main.py}