Skip to content

Instantly share code, notes, and snippets.

@bebosudo
Last active November 20, 2018 11:25
Show Gist options
  • Save bebosudo/c81697bec5bd905ce2d055640fdda1d4 to your computer and use it in GitHub Desktop.
Save bebosudo/c81697bec5bd905ce2d055640fdda1d4 to your computer and use it in GitHub Desktop.
Setup virtualenvwrapper on Ubuntu 16.04 or Fedora 25+

Setup virtualenvwrapper on Ubuntu 16.04 or Fedora 25+

Install virtualenvwrapper, which eases the handling of Python virtualenvs (sort of Virtual Machines for Python packages).

$ pip3 install --user virtualenvwrapper

Add to your ~/.bashrc, or better, to your ~/.bash_profile:

export WORKON_HOME=~/.venvs/
# Point this to your python3 executable, or ignore this line if you want to
# create default venv based on the default python exe.
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
# Find out where virtualenvwrapper.sh is located; you can use
#   $ find / |grep virtualenvwrapper.sh
# or alternatively:
#   # updatedb         # this has to be performed by root, and takes a while
#   # locate virtualenvwrapper.sh
# If you installed virtualenvwrapper using `$ pip install --user`, it should
# be stored in the following location.
source $HOME/.local/bin/virtualenvwrapper.sh
# or let bash find it
# source $(which virtualenvwrapper.sh)

Then manually create the ~/.venvs/ folder, and reload the ~/.bashrc settings file, so that changes take effect.

$ mkdir ~/.venvs/
$ source ~/.bashrc

Now you can easily create and manage virtual environment using the workon command. Example:

# Create a new virtualenv with:
$ mkvirtualenv new-env
# And to load the virtualenv:
$ workon new-env

(new-env)
$ 

Now everything you install with pip is installed within the venv currently loaded:

(new-env)
$ pip install numpy
...
Successfully installed numpy-1.13.3
$ find ~/ |grep numpy
$HOME/.venvs/new-env/lib/python3.5/site-packages/numpy
...

Enjoy!

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