Skip to content

Instantly share code, notes, and snippets.

@paulozullu
Created October 18, 2017 15:12
Show Gist options
  • Save paulozullu/68f518e2e378219f54c388b4f80a3261 to your computer and use it in GitHub Desktop.
Save paulozullu/68f518e2e378219f54c388b4f80a3261 to your computer and use it in GitHub Desktop.
Add the ability of bash script to recognize workon command.

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:

# 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 PATH
workon $1
python $2
deactivate

And could be used simply like venv-run.sh my_virtualenv /path/to/script.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment