Skip to content

Instantly share code, notes, and snippets.

@VictorNS69
Forked from miranda-zhang/virtualenv.md
Last active March 15, 2024 02:47
Show Gist options
  • Save VictorNS69/25f82339708714628177a7e2bd566afc to your computer and use it in GitHub Desktop.
Save VictorNS69/25f82339708714628177a7e2bd566afc to your computer and use it in GitHub Desktop.
How to install virtualenv and virtualenvwrapper

Install virtualenv and virtualenvwrapper

Install both packages:

sudo apt install virtualenvwrapper
sudo apt install virtualenv

(recomended if have multiple apps running on different enviroments)

$ pip3 install virtualenv 
$ pip3 install virtualenvwrapper

$ mkdir ~/.virtualenvs

Add these lines to the end of ~/.bashrc so that the virtualenvwrapper commands are loaded.

    export WORKON_HOME=~/.virtualenvs
    . /usr/local/bin/virtualenvwrapper.sh

Exit and re-open your shell, or reload .bashrc with the command

source ~/.bashrc

Virtualenvwrapper is a utility on top of virtualenv that adds a bunch of utilities that allow the environment folders to be created at a single place, instead of spreading around everywhere.

Create a virtual envirioment to work under:

$ mkvirtualenv codebench 

See Virtualenvwrapper on Ubuntu for more details.

Virtualenvwrapper commands

lsvirtualenv
mkvirtualenv [mkvirtualenv-options] [virtualenv-options] <name>
    [mkvirtualenv-options]
    -h  Print help text.
workon [<name>]
deactivate
rmvirtualenv <name>

Setup a new virtualenv with python3

$ mkvirtualenv --python=/usr/bin/python3 <env name>

Windows

https://github.com/davidmarble/virtualenvwrapper-win

pip install virtualenvwrapper-win

At this stage virtualenvwrapper commands should work in cmd, but not in git bash.

https://www.tumblingprogrammer.com/setting-up-windows-for-python-development-python-2-python-3-git-bash-terminal-and-virtual-environments/

echo "source virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc

Now it should work in both, but the default environment lists are stored in different files, so lsvirtualenv would show different results.

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