As a developer and scientist, I prefer to use Linux. As an engineer I am sometimes forced to use Windows. Well I recently decided to figure out how to setup Windows (Win7 in this case) for Django development. It turns out, it actually isn't too hard.
pip and fabric on Windows
Some critical development tools are pip, virtualenv, and fabric. If you install in the following order, you can avoid headaches:
- Install Python. I use
Enthought's EPD freeAnaconda for access to scipy, numpy, and iPython, but the normal installer from python.org would work too
- Download and unzip pip. Install by going into the expanded directory and running
python setup.pyin a command prompt.
- Download and install PyCrypto for windows
If you want a raw-ish Windows experience, you can now use pip to install fabric, virtualenv, and virtualenvwrapper-win.
pip install fabric virtualenv virtualenvwrapper-win from a command prompt. I like to use Cygwin because I'm more comfortable at a *nix prompt, instructions are below.
At this point you have
virtualenvwrapper, which are standard tools for modern web development. I've noticed that things behave better if I don't create my
mkvirtualenv from the
virtualenvwrapper package. Instead, go to
C:\User\<username>\Env (or other
%VIRTUALENV_HOME% location) and use
virtualenv to start a new environment. Doing this allows
workon command to work.
virtualenv and virtualenvwrapper with cygwin
If you want to use Cygwin, follow the above steps 1-3, then:
- Set the
%PYTHONHOME%system variable to the python base directory, (i.e.
C:\Python27\) and adding the python base directory and script directory (i.e.
C:\Python27\Scripts) to your %PATH% system variable.
- Install Cygwin WITHOUT Python. The previous step tells Cygwin to use the Windows binary.
- Install Cygwin-Virtualenvwrapper using
pip install https://bitbucket.org/cliffxuan/virtualenvwrapper-for-cygwin-windows-python/get/tip.tar.gz
pip install virtualenvwrapper-win
- Make a symlink between Cygwin's virtualenvhome directory and Windows's using
ln -s /cygdrive/c/Users/<USER>/Envs/ ~/.virtualenvs
Add the following to Cygwin's
export VIRTUALENVWRAPPER_PYTHON="/cygdrive/c/Python27/python.exe" export VIRTUALENVWRAPPER_VIRTUALENV="/cygdrive/c/Python27/Scripts/virtualenv.exe" source $HOME/cygwin_virtualenv/virtualenvwrapper.sh
Adjust the variables to point at the appropriate executables.
If you installed in order, cygwin and Windows should play nicely with their shared virtualenvs. Be sure to heed my advice above about creating
virtualenvs though. You can now install other handy libraries, like fabric.
Warning: by default, the Cygwin
python command does not initiate the normal interactive shell. Use
python -i to get python to run as expected.
Django and Python on Windows
Whether or not you set up Cygwin, you now have two options for installing Python libraries: (1) from Windows installers (officially from the package website or unofficially from Christoph Gohlke) and (2) from
pip. For bigger libraries like PIL, I prefer to use the windows installer into my global Python
site-packages directory. For smaller libraries like Django apps, I use
pip from within my
virtualenv. Just take care when installing windows packages globally; if the library gets gunked up, the easiest solution is often to uninstall Python completely and start over.
In any case, now you just need a good text editor and version control system and you can be a full fledged django and/or python developer on Windows, with a variety command prompt options to test your prototypes and keep your environments isolated.
Update for Msys / MsysGIT (8 May 2013)
My old (6 years is a pretty long life by modern technology standards!) laptop bit the dust, and I ended up getting a new laptop and trying to use the official Windows version of git (
msysgit) in the new installation. You can follow the above instructions to get through getting
virtualenvwrapper-win installed. Then...
msysgit. I recommend installing it in a path without any spaces-- I had issues getting through Step 4 (below) using the default path.
- Copy the following files from the msys extnernal binary packages's
msys\binfolder to your git installation's
Make the following changes to your git's
export MSYS_HOME=</path/to/Git> export WORKON_HOME=$HOME/Envs source </path/to/Python/>/Scripts/virtualenvwrapper.sh
It works surprisingly quickly without much instability, and gives you the option to run all development commands from either the windows command prompt or the msys prompt.