wryFi: word

facetious fidelity

since 2008

Most Recent

Categories

Tags

Links

virtualenvwrapper wrapper

Mon Nov 24 2014

in

programming
python virtualenv

support multiple python versions

I'm running Arch linux on my laptop these days, and it defaults to python 3. Occasionally I have development work that still needs to happen in python 2. I like to use virtualenv, and also value the additional functionality added by virtualenvwrapper. But Arch doesn't include a package of virtualenvwrapper for python 2 (nor is this easily done). My workaround is to create a virtualenvwrapper wrapper.

First install both versions of virtualenv:

  1. pacman -S python-virtualenv
  2. pacman -S python2-virtualenv

Next, have a look at my previous post on isolating python environments in Arch. Once you've got that set up, you can pip2 install virtualenvwrapper to get the python 2 version installed under /usr/local.

Finally, create a simple wrapper script for python 2 in a convenient location (e.g. ~/bin/v2) with the following content:

#!/bin/bash
VIRTUALENVWRAPPER_PYTHON="$(which python2)"
VIRTUALENVWRAPPER_VIRTUALENV="$(which virtualenv2)"
. /usr/local/bin/virtualenvwrapper.sh
"${@}"

Now you can use all of the normal virtualenvwrapper commands for python 2 by prefixing them with your wrapper script, e.g. v2 mkvirtualenv python2env. To use python 3, just call the virtualenvwrapper commands as normal, e.g. mkvirtualenv python3env.