Skip to content

Instantly share code, notes, and snippets.

@pmav99
Last active August 29, 2015 14:24
Show Gist options
  • Save pmav99/3d39977c86ce53886eb7 to your computer and use it in GitHub Desktop.
Save pmav99/3d39977c86ce53886eb7 to your computer and use it in GitHub Desktop.
virtualenv + virtualenvwrapper instructions

Tested under zsh, should work under bash too.

  1. Install virtualenv & virtualenvwrapper. Depends on the distribution.

  2. Put in .zshrc (.bashrc if you use bash):

    # Virtualenvs
    if which virtualenvwrapper.sh &> /dev/null; then
        mkdir -p $HOME/Prog
        export WORKON_HOME=$HOME/.virtualenvs
        export PROJECT_HOME=$HOME/Prog/venvs
        source $(which virtualenvwrapper.sh)
    fi
  3. Create a new virtualenv using the command mkproject project_name (obviously you will change project_name to something meaningful).

  4. Now the virtualenv is activated and you have cd-ed into $PROJECT_HOME/$project_name. You can start your development (e.g. install packages using pip install package_name etc).

  5. When you are done you just write deactivate. This will restore the default python installation into use.

  6. If you want to remove a virtualenv you write rmvirtualenv project_name. This will delete the $HOME/.virtualenvs/$project_name directory but not the $HOME/Prog/venvs/$project_name one. I.e. your code is safe!

  7. The mkproject command uses the default python installation. This may be python2 or python3 depending on the distribution. You can explicitly specify a python version using mkproject -p /usr/bin/python3 project_name.

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