Installing Django on windows

Well if you have decided to install Django, by now you must be knowing Django is a Python based web framework and in today’s post I’ll run through Django installation process on Windows including dependencies (like installation of Python, database, database adapters and other important libraries that Django depends on). If you already have Python installed, then skip Python installation section.

Installing Django/Python/Python modules is same in all versions of windows and hence below steps are valid for Windows XP and Windows Vista. Those who are using Windows Vista, just make sure you run all installations as Administrator ( Right click setup file and run as administrator )

Let’s begin by installing Python (If you already have a working Python installation, skip this section)

Python Installation:

  1. Download latest Python binary for Windows from http://python.org/download/. Make sure you are using right binary file for your processor and always get the latest release
  2. Install Python by double clicking the setup file you have downloaded in above setup and follow onscreen instructions.(Use defaults if possible or make sure you don’t have spaces and special characters in your installation path)
  3. Edit your path settings and add Python to same. To edit path settings, right click My Computer and select properties which will open other window. Click advanced tab and then Environment variables and select PATH and click edit and add python installation path and it’s scripts (In my case C:\Python26\Tools\Scripts;C:\Python26; ) and click ok to save and comeout of that properties window by clicking ok.
  4. Launch command prompt and then type python, you should see message like below. (If you get command not found, then most likely path is wrongly setup)

Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>exit( )
*NOTE: Version numbers and processor models may be different

If you face any problem , make sure you have set PATH variable correctly.

Once we have Python working fine, we will move to next step to setup Django.

Django Installation:

  1. Download Django from Django Site . There are two versions available,  Latest official version (Recommened for production) which can be downloaded directly or development version through svn. You need SVN client ( Tortise SVN, Free SVN client for Windows) .
  2. If you are going with official version, extract the package and copy only the django(leave the docs, tests and examples etc.,) directory to site-packages ( site-packages will be under your Python installation path ( <python-installation path>\Lib\site-packages\ )
  3. Add django to Environmental variables ( Like you did for Python installation step 3), just edit path settings and add <python-installation path>\Lib\site-packages\django\bin;
  4. That’s it we are almost done installing django, Launch command prompt and type django-admin.py command and it should throw output similar to Type ‘django-admin.py help’ for usage.
  5. Launch Python interpreter and run the commands import django and django.get_version() and output should look like below

D:\PROFILES\chundis>python
Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import django
>>> django.get_version()
’1.0.1 final’
>>> exit()
D:\PROFILES\chundis>

If you have any problems with step 4 and 5 of Django installation , just make sure you have copied the correct django directory to site-packages.

We are done with Django installation but we need to install dependancies before we can start writing Django Apps.

We still need to install Database and database driver for Python, so that our Django apps can use Database. Also we need to install Python Imaging Library (PIL) for Django to validate images and without this module, you won’t be able to use ImageField()

Database Installation:

If you don’t have any preference, then try mySQL or Postgres.  Postgres comes with pgAdmin by default (A GUI based app to manage database) and for mySQL, there are GUI tools like phpMyAdmin and SQLyogi. I prefer mySQL with SQLYog Community Edition

  1. mySQL for windows can be downloaded from  http://dev.mysql.com/downloads/ and Postgres for windows can be download from http://www.postgresql.org/download/windows
  2. Both the databases has Windows installers, so installation is pretty much like any other Windows application. Just double click the installer and follow onscreen instructions. There will be a option to select run as service (so make sure you select that, so it will run automatically on windows startup)

Next we need to install Python driver(adapter/module) for Python to communicate with database,

Database Driver installation

Depending on the choice of database you made during previous section (Database installation), you need to install Database driver for Python.

  1. If you are using mySQL then Python module for mySQL can be download here ( http://sourceforge.net/projects/mysql-python/ ) or if you decide to use Postgres, then  Python module for PostGre can be downloaded here ( http://www.pygresql.org/readme.html#home-sites-of-the-different-packages ). Make sure you download the latest driver for your Python version. (Most of the drivers are packaged different for different Python versions)
  2. Install database driver by executing the binary. (VIsta users, use run as administrator)
  3. To test the database and database driver
    1. Create a database
    2. Launch command prompt and create django project using django-admin.py startproject <projectname>
    3. Change Database settings in settings.py under project directory above command created.
    4. cd (Change Directory) to you project directory execute python manage.py validate and it should display 0 errors found

And finally we need Imaging library to support images.

Python Imaging Library installation
On windows this is a straight forward installation, though it troubles a lot on Unix flavor OS to get jpeg support.

  1. Download the windows executable from http://www.pythonware.com/products/pil/ and execute it to install PIL (Vista users, run as administrator)

That’s it, your windows box is now Django ready and you can start writing Django apps.

4 thoughts on “Installing Django on windows

  1. A couple of points to add in order to have a more complete development platform for django on windows:

    1. To develop and test with “File Fields” and “Image Fields” you’ll need either to install Apache or, at least, follow the instructions in
    http://docs.djangoproject.com/en/dev/howto/static-files/

    2. if you need to use internationalization (i18n) you’ll need to install gettext. You can find it here: http://gnuwin32.sourceforge.net/packages/gettext.htm
    you also need to have it in your windows path

  2. Great simple install guide! Thanks

    But all was well until Database driver installation, test database; 1).Install Database? Where with what? For a non-programmer that needs expanding……….

  3. Simple and straight forward method to install and test Django. Helped me a lot.

    Thank you for sharing !!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>