Search code examples
bashvirtualenvwrapper

How to call cdvirtualenv from a bash script?


The virtualenv package is set up from .bashrc by sourcing /usr/share.../virtualenvwrapper.sh. This file defines a number of functions, among those cdvirtualenv:

function cdvirtualenv {
    virtualenvwrapper_verify_workon_home || return 1
    virtualenvwrapper_verify_active_environment || return 1
    virtualenvwrapper_cd "$VIRTUAL_ENV/$1"
}

How do I call this function from my own script file?

Simply calling it:

#!/bin/bash

cdvirtualenv

gives me:

/srv/bin$ ./echotmp.sh
./echotmp.sh: line 3: cdvirtualenv: command not found

Solution

  • I hope this will help you, to call cdvirtualenv from a bash script, you can use the source command to execute the virtualenvwrapper.sh script and then call cdvirtualenv with the name of the virtual environment as an argument.