Skip to content

Instantly share code, notes, and snippets.

@miranda-zhang
Last active July 30, 2019 12:51
Show Gist options
  • Save miranda-zhang/90554d1fd66b81f44e119ffabed07e0b to your computer and use it in GitHub Desktop.
Save miranda-zhang/90554d1fd66b81f44e119ffabed07e0b to your computer and use it in GitHub Desktop.
virtualenv and virtualenv wrapper commands

Install virtualenv and virtualenvwrapper

(recomended if have multiple apps running on different enviroments)

$ pip install virtualenv virtualenvwrapper

$ mkdir ~/.virtualenvs

$ export WORKON_HOME=~/.virtualenvs

Add this line to the end of ~/.bashrc so that the virtualenvwrapper commands are loaded.

. /usr/local/bin/virtualenvwrapper.sh

Exit and re-open your shell, or reload .bashrc with the command

source ~/.bashrc

Virtualenvwrapper is a utility on top of virtualenv that adds a bunch of utilities that allow the environment folders to be created at a single place, instead of spreading around everywhere.

Create a virtual envirioment to work under:

$ mkvirtualenv codebench 

See Virtualenvwrapper on Ubuntu for more details.

virtualenvwrapper commands

lsvirtualenv
mkvirtualenv [mkvirtualenv-options] [virtualenv-options] <name>
    [mkvirtualenv-options]
    -h  Print help text.
workon [<name>]
deactivate
rmvirtualenv <name>

Setup a new virtualenv with python3

$ mkvirtualenv --python=/usr/bin/python3 <env name>

windows

https://github.com/davidmarble/virtualenvwrapper-win

pip install virtualenvwrapper-win

At this stage virtualenvwrapper commands should work in cmd, but not in git bash.

https://www.tumblingprogrammer.com/setting-up-windows-for-python-development-python-2-python-3-git-bash-terminal-and-virtual-environments/

echo "source virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc

Now it should work in both, but the default environment lists are stored in different files, so lsvirtualenv would show different results.

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