Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install virtualenv on Ubuntu + ZSH (on WSL)

Virtualenv on WSL with ZSH

Install PIP

sudo apt install python-pip
sudo apt install python3-pip

pip --version
pip3 --version

Install virtualenv

pip install virtualenv
pip install virtualenvwrapper

Edit .zshenv

# Add .local/bin to the path
export PATH=~/.local/bin:$PATH

Create .venv folder

mkdir ~/.venvs

Edit .zshrc

Add virtualenv to the plugin list:

plugins=(
  git virtualenv
)

And add the following at the end of the file:

# Virtual env
export WORKON_HOME=~/.venvs
source ~/.local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=~/.venvs

Edit ZSH virtualenv plugin

Comment out export VIRTUAL_ENV_DISABLE_PROMPT=1.

nano ~/.oh-my-zsh/plugins/virtualenv/virtualenv.plugin.zsh

Refresh source

source ~/.zshenv
source ~/.zshrc

Test virtual env

cd /mnt/c/code/<your-project-folder>
mkvirtualenv testenv
workon
deactivate

Optional: commnand aliases

You can add the following useful aliases to ~/.aliases. Taken from here: https://gist.github.com/bbengfort/246bc820e76b48f71df7

alias venv="workon"
alias venv.exit="deactivate"
alias venv.ls="lsvirtualenv"
alias venv.show="showvirtualenv"
alias venv.init="mkvirtualenv"
alias venv.rm="rmvirtualenv"
alias venv.switch="workon"
alias venv.add="add2virtualenv"
alias venv.cd="cdproject"
alias venv.cdsp="cdsitepackages"
alias venv.cdenv="cdvirtualenv"
alias venv.lssp="lssitepackages"
alias venv.proj="mkproject"
alias venv.setproj="setvirtualenvproject"
alias venv.wipe="wipeenv"
@Bishwas-py

This comment has been minimized.

Copy link

@Bishwas-py Bishwas-py commented Apr 27, 2021

How about simply installing virtualenv similar to this: How to install python virtualenv in wsl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment