Setting Up a Django Development Environment in Windows Using Cygwin

I love GNU/Linux.  I use it every day, all day, and I have very little interest in using any other operating system.  With that being said, not everyone shares my feelings, and when I recently volunteered to mentor a group of up and coming developers, I realized that they have enough to worry about trying to learn Python and Django, without me trying to convince them to switch to an entirely new operating system.  So in the interest of baby steps, here is the guide I put together to help them get their Python and Django development environments setup on their existing Windows computers.

Cygwin FTW!

Cygwin is described as "A Unix-like environment and command-line interface for Microsoft Windows", which means that we can setup all of our tools to function as if they were running in a Linux environment, but on Windows.  It's certainly possible to get all of your Python and Django tools and libaries installed on Windows, but if we get you setup using Cygwin, then we can use the same instructions for setting everything else up regardless of what OS you are using.  

So, let's install Cygin with the components we want.  Download the version of Cygwin that matches your system architecture from here:

For x86 versions of Windows, us, and for 64bit versions of Windows, use

Instead of posting screenshots of every step of the install, I'll just say that you can select most of the defaults when clicking through the installer, except when you get to the Select Packages part of the installer, search for and select the following packages for installation:

  • git
  • python
  • python-setuptools
  • openssh

Once Cygwin has installed, you should have a new desktop icon that you can use to launch Cygwin.  Go ahead and double click that and you should see a terminal window like this:

From here, we can install our toolset and get started with developing python.

Extra Credit

Ok, so for extra credit we can dive into the toolset that I strong suggest you use for your python development  Here's a list:

  • pip - A tool for installing and managing Python packages.  This tool makes it easy for me to say "go install Django" and all you have to do is run "pip install django"  It's pretty awesome.
  • virtualenv (Virtual Environments) - Python allows you to use libraries (awesome code written by other people), but it's a pain dealing with different versions of different libraries for each of your projects.  Virtualenv lets you create different environments to install your libraries into for each project.  It's really handy, trust me.
  • virtualenvwrapper - A handy set of shortscuts for working with your virtual environments.
  • git - Version control, this is also super handy.

So, let's install pip, virtualenv and virtualenvwrapper.  Just run "easy_install pip virtualenv virtualenvwrapper" and if you get any errors, run the same command a few more times until you don't get any errors.  At the time of this writing there's something screwy with either virtualenv or virtualenevwrapper that causes it to return errors even when it's installing correctly.

How do you use these tools?  Well first let's activate virtualenvwrapper, run this command:

echo "source" >> ~/.bashrc

This will add activate the virtualenvwrapper functionality every time you start your shell.  Now close Cygwin and open it up again.  Type "workon" and press enter and if you don't see a "command not found" error, you did everything right.  From here we'll create our first virtual environment by running the command "mkvirtualenv learnpython".  This will create and activate a virtual environment called "learnpython".  Now let's use pip to install a library in this environment.  Why not Django?  Run the command "pip install django" and it should tell you (among other things) "successfully installed django"  To make sure it's installed correctly, run the command "" and if you see the error " command not found" then something went wrong.  What you should see is a list of available commands supported by, which we'll look at in another post. 

So, if everything went well, we should have virtualenv, virtualenvwrapper, and pip all setup and working together.  Next time you open Cygwin and you want to use the same "learnpython" virtual environment, just run the command "workon learnpython" and it will activate that environment.  To deactivate the environment, either work on (or create) a different environment, or run the command "deactivate", which will exit the current virual environment.  

Previous entry

Similar entries