Installation

 1# macOS
 2brew install python3 python-pip
 3
 4# Ubuntu
 5sudo apt install python3 python-pip
 6
 7# Update pip to the latest version
 8pip install --upgrade pip setuptools wheel
 9pip3 install --upgrade pip setuptools wheel
10
11# Install virtualenvwrapper
12pip3 install virtualenv virtualenvwrapper

Create projects directory

1mkdir ~/Projects

Configure .profile (Bash) or .zprofile (ZSH):

1# needed for virtualenvwrapper
2export WORKON_HOME=$HOME/.virtualenvs
3export PROJECT_HOME=$HOME/Projects
4export VIRTUALENVWRAPPER_PYTHON=/bi/home/USER/.linuxbrew/bin/python3
5export VIRTUALENVWRAPPER_VIRTUALENV=/bi/home/USER/.linuxbrew/bin/virtualenv
6export PIP_REQUIRE_VIRTUALENV=true
7source /bi/home/USER/.linuxbrew/bin/virtualenvwrapper.sh

Reload profile

1source ~/.profile
2source ~/.zprofile

Make a new project

  • The command will create a python virtual environment by running mkvirtualenv.
  • Then it will creates a project directory and will turn to that directory.
1# using the default python version
2mkproject projectName
3
4# using specific python version
5mkproject -p `which python` projectName

To delete a project

1rmvirtualenv projectName

Bonus

If you are using ZSH shell with prezto (recommended), you can change prezto prompt to indicate the virtual environment currently in use. You need to edit prompt_sorin_setup as follow1 :

1cd $HOME/.zprezto/modules/prompt/functions/
1# Check for activated virtualenv
2if (( $+functions[python-info] )); then
3python-info
4fi
5
6# Compute slow commands in the background.
1     'status' '$(coalesce "%b" "%p" "%c")%s%A%B%S%a%d%m%r%U%u'
2
3# %v - virtualenv name.
4zstyle ':prezto:module:python:info:virtualenv' format '(%v)'
5
6# Define prompts.
7PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}$python_info[virtualenv] ${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} '

[1] How to display current virtualenv in your ZSH Prezto theme