virtualenvwrapper code example
Example 1: virtualenvwrapper
$ pip install virtualenv
$ pip install virtualenvwrapper
// Append ~/.bashrc
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/$HOME/.local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
Example 2: how to use virtualenvwrapper
# install Virtual Environment alternative to virtualenv
pip install virtualenvwrapper
# modify your .profile file
# find out where virtualenvwrapper.sh file is by issuing which command
# source it as shown below
source /usr/local/bin/virtualenvwrapper.sh
# setup an environment
mkvirtualenv dev_env1
mkvirtualenv dev_env2
mkvirtualenv dev_env3
mkvirtualenv dev_env4
# create list of your projects, project1...projectN
mkproject project1
mkproject -p python3 project2 # this project is for python 3 only
mkproject project3
mkproject projectN
# go to the folder where you have cloned an existing repo
# and run the command to bind that project to this environment
setvirtualenvproject
# get list of all environments
workon
# choose a project to work on based on previous output
# say you have dev_env1, dev_env2, dev_env3... dev_envN
# state the name of the project to work on
workon dev_env1
# other tasks
# remove un-needed environments
rmvirtualenv dev_env4
# build a temp environment if needed
mktempenv
# .profile needs this variables set for export
# i.e. export WORKON_HOME="/home/rajib2k5/envs"
# export PROJECT_HOME="/home/rajib2k5/dev"
# in order to leave an environment, run the command below
deactivate
Example 3: virtualwrapper
$ pip install virtualenvwrapper
...
$ export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv env1
Installing
setuptools..........................................
....................................................
....................................................
...............................done.
virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/predeactivate
virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postdeactivate
virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/preactivate
virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postactivate New python executable in env1/bin/python
(env1)$ ls $WORKON_HOME
env1 hook.log