Skip to content

Instantly share code, notes, and snippets.

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:

  git virtualenv

And add the following at the end of the file:

# Virtual env
export WORKON_HOME=~/.venvs
source ~/.local/bin/
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

Optional: commnand aliases

You can add the following useful aliases to ~/.aliases. Taken from here:

alias venv="workon"
alias venv.exit="deactivate"
alias venv.init="mkvirtualenv"
alias venv.rm="rmvirtualenv"
alias venv.switch="workon"
alias venv.add="add2virtualenv"
alias venv.cdsp="cdsitepackages"
alias venv.cdenv="cdvirtualenv"
alias venv.lssp="lssitepackages"
alias venv.proj="mkproject"
alias venv.setproj="setvirtualenvproject"
alias venv.wipe="wipeenv"

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