Alexandre M. Savio

Sat 08 February 2014


How to create virtualenvs with Virtualenvwrapper

Virtualenv and virtualenvwrapper

Install virtualenv and virtualenvwrapper

sudo apt-get install python3-pip
sudo pip3 install virtualenv virtualenvwrapper

Virtualenvwrapper .bashrc setup:

echo "export WORKON_HOME=~/envs" >> ~/.bashrc
echo "source /usr/local/bin/" >> ~/.bashrc
echo "export PIP_REQUIRE_VIRTUALENV=true" >> ~/.bashrc
source ~/.bashrc

Basic usage commands

Create a virtualenv:

 mkvirtualenv <env name>

Activate a virtualenv:

  workon <env name>

Install a package in the activated virtualenv

pip install <package name>

Go to its directory after activating it


Set a working directory as a project of the virtualenv

cd <project dir>
setvirtualenvproject $VIRTUAL_ENV $(pwd)

Get a list of the Python modules and versions installed in an activated virtualenv

pip freeze

To deactivate a virtualenv


Run ipython within the virtualenv:

alias ipy=\"python -c 'import IPython;

IPython.terminal.ipapp.launch_new_instance()’" ipy

Run ipython with other options:

Add this to .bashrc:

alias ipy="python -c 'import IPython;


function ipyqt(){
    python -c 'import IPython;

IPython.start_ipython([‘”’“‘qtconsole’”’”’]);’ }

function ipynote(){
    python -c 'import IPython; IPython.start_ipython(['"'"'notebook'"'"']);'

Another interesting option:

Download a virtualenv script:


Give it execution permission:

chmod +x

Create the virtualenv:

./ <env_name> -p <path_to_python>


source <env_name>/bin/activate

Python script shebang to use the enviroment:


REFERENCES: for-data-analysis-on-osx/

Go Top