Virtualenv helps a lot when you work with various Python projects or when you have to use specific packages or different Python versions. In this tutorial, we are going to install Virtualenv on Ubuntu 14.04 and configure it on zsh.
Install pip, virtualenv and virtualenvwrapper
sudo apt-get install -y python-pip python-virtualenv virtualenvwrapper
Create the directory for our virtual environments
mkdir ~/.venvs
Configure ZSH - .zshrc
Edit the file ~/.zshrc and paste the content below:
export WORKON_HOME=~/.venvs
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=~/.venvs
Create our first virtualenv
~ ❯❯❯ mkvirtualenv myproject ⏎
New python executable in myproject/bin/python
Installing setuptools, pip...done.
(myproject)~ ❯❯❯ deactivate
~ ❯❯❯ workon myproject
(myproject)~ ❯❯❯ pip install django
Downloading/unpacking django
Downloading Django-1.7.4-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
(myproject)~ ❯❯❯
List your virtual environments
~ ❯❯❯ workon ⏎
angular
fabric
goate
myotherproject
myproject
stress
Notes
To leave your current virtualenv use deactivate
To change between virtualenvs use workon name
That’s all. If you want you can read more about Virtual Environments here