For a long time I’ve allowed myself to suffer without virtualenvwrapper on Windows because I didn’t think it would work. It turns out I am not only wrong, but that I can use it in all of my daily activity.
Virtualenvwrapper provides convenience commands and a central location for storing Python virtualenvs. Virtualenvs are an invaluable tool for playing around with incompatible Python modules and testing. If you’re not using them, you should start now. Virtualenvwrapper will save you some typing.
Doug Hellmann’s original virtualenvwrapper now supports MSYS environments out of the box, and David Marble has graciously suffered the unpleasantries of Windows batch file voodoo to bring up his fork virtualenvwrapper-win. Setup for both is quite straightforward and can be done in only a few minutes.
Virtualenv for cmd.exe
> pip install virtualenvwrapper-win > pyassoc
As an added bonus, virtualenvwrapper-win installs
whereis in your path, which is akin to
which on Unix, though it lists all locations. Since it seems I am incapable of remembering to place the batch file I wrote in my path to emulate which, this is quite convenient.
Enabling virtualenvwrapper on msysgit bash
Virtualenvwrapper will run on msysgit bash, or an install of msys bash. Unfortunately, the experience isn’t quite out of the box because msysgit does not include mktemp.exe. Otherwise, you can generally follow the instructions.
There are three steps:
- Install virtualenvwrapper
- Configure your .bashrc
- Install mktemp.exe
The first step is no different than on Linux:
$ pip install virtualenvwrapper
Next, configure a few extra variables in your .bashrc. msysgit’s bash uses your Windows home directory (
%USERPROFILE%), so you’ll set
MSYS_HOME to it.
if [ "$MSYSTEM" ]; then export MSYS_HOME=/c/MinGW/msys/1.0 export WORKON_HOME=$HOME/.virtualenvs if [ -e /c/Python27/Scripts/virtualenvwrapper.sh ]; then source /c/Python27/Scripts/virtualenvwrapper.sh fi fi
Replace your Python location above accordingly. Also, make sure that
MSYSTEM is set to
MINGW32 in your msysgit bash environment.
Finally, the hard part. To get mktemp, you’ll need to install the real MSYS distribution and download it. There’s certainly a shortcut here, but it was far easier for me to just do this than to figure out how to find where the MSYS project stores the binary. I’ve always found the MSYS website and Sourceforge page incomprehensible. So, download the latest MSYS installer and it let install the defaults. Open up your new MSYS bash prompt and grab mktemp:
$ mingw-get msys-mktemp
You’ll now have a fresh copy of mktemp.exe, whose slightly confusing default location will be
C:\MinGW\msys\1.0\bin. Copy this binary into your msysgit’s bin directory. You’re now ready to go. Once you start up msysgit’s bash prompt with your new .bashrc in
$HOME, you should be able to create a new virtualenv with
Update 02/09/2013: As pointed out by David Marble, the full install of MSYS is not necessary to get
mktemp.exe. I’ve confirmed that I am able to get virtualenvwrapper fully working just by downloading mktemp from Sourceforge and extracting directly into my msysgit bin directory.