Automatically activate your virtualenv project

Virtualenv and Virtualenvwrapper are fantastic tools. But have you ever wondered how to automatically load the environment when you cd into your project’s directory? I bet you’ve probably crawled the web and found solutions like aliasing “cd” or making some sort of bash function. But really, it should be easier.

So have you heard about ruby’s rvm? Besides being a ruby version manager, it lets you create directory-specific “.rvmrc” files which execute every time you cd into a directory.

If you don’t have rvm already, install it and learn ruby. Then try this when you decide you like python better (hah!):

    proj_name=PROJECT_NAME
    if [ "${VIRTUAL_ENV##*/}" != "$proj_name" ]
    then
      workon "$proj_name"
    fi
GitHub Thingiverse StackOverflow Twitter LinkedIn Facebook

Blog Posts