- Organizes all of your virtual environments in one place.
- Wrappers for managing your virtual environments (create, delete, copy).
- Use a single command to switch between environments.
- Tab completion for commands that take a virtual environment as argument.
- User-configurable hooks for all operations (see Per-User Customization). 6.Plugin system for more creating sharable extensions (see Extending Virtualenvwrapper).
pip install virtualenvwrapper
We need to specify the directory that’ll be the home of all of our virtual environments. To do that we need to set an environment variable
WORKON_HOME and set it’s value to our virtualenv home directory. We also need to source the actual virtualenvwrapper shell script that’ll allow us to run virtualenvwrapper commands.
# Set the WORKON_HOME variable for virtualenvwrapper export WORKON_HOME="~/.virtualenvs" # Source the virtualenvwrapper shell script to be able to run commands source /usr/local/bin/virtualenvwrapper.sh
All in one command:
echo -e '\n# Set the WORKON_HOME variable for virtualenvwrapper \nexport WORKON_HOME="~/.virtualenvs"' >> ~/.bash_profile && echo -e '\n# Source the virtualenvwrapper shell script to be able to run commands \nsource /usr/local/bin/virtualenvwrapper.sh' >> ~/.bash_profile && source ~/.bash_profile
tab for command auto-completion (or make an alias for the command).
Creating a virtual environment also automatically activates it (contrary to virtualenv).
to deactivate environment:
change your current dir to virtualenv dir
get a list of all the virtual environments:
list packages for the environment:
go to site packages directory:
associating a project (code) foler with a virtual environment
Activate/switch to the virtual environment and cd to the project folder and run the command
setvirtualenvproject while you have the virtualenv activated. For example:
(foo)[~] $ cd ~/Sandbox/foo (foo)[~/Sandbox/foo] $ setvirtualenvproject
setvirtualenvproject creates a
.project file in the virtualenv directory and adds the path of the project to it. To remove the project connection all you have to do is delete this file.
Hooks basically let you run commands at certain intervals/places in the setup.
postmkvirtualenv lets you run commands after an env is created,
postactivate lets you automatically run commands right after an env is activated.
predeactivate lets you run a command before an env is deactivated. These hook files are located in