How to install Python and Django in Windows Vista

This is possibly one of the easier ways to install a Django development environment for your Windows Vista 32-bit machine. (Alternatively, there’s Instant Django, it’s much like Instant Rails where you just extract it out and can start immediately.)

0. Objective

Objective is to create an application with Django. This guide assumes you have no knowledge in Python, Django or Windows Vista. It does, however, assumes you know and already set up MySQL nicely. Just for you information, I use XAMPP Lite for development in PHP. I run XAMPP Lite’s MySQL and administer my MySQL with phpMyAdmin.

Let’s look at the required downloads. We will need 3 things:

  1. Python 2.6: Django requires Python to function, we’ll grab the latest Windows binary here. (Get the one that says something like Python 2.6.2 Windows installer)
  2. Django: You can get Django here. Use option 2 if you don’t know what SVN is about.
  3. MySQL for Python: This lets Python use MySQL, it does not install MySQL. You can get it here. (Download the one that says ‘MySQL-python-1.2.2.win32-py2.5.exe’ inside the ‘mysql-python‘ package.

1. Installing Python 2.6


The installer is pretty straightforward. This guide assumes you install in ‘C:\Python26\’, the default installation directory. (Do not install in your Program Files as Program Files somehow has lesser access rights.) You should not encounter any error.

After completion of the Python 2.6 installation, set up your environment variables. We want to be able to just type ‘django-admin.py startproject mysite’ in the command prompt. In order to do that, you will have to specify the directory that Windows Vista can search for to find ‘django-admin.py’.

We can do so by going to your Control Panel and type ‘environ…’ at the search area. We’ll get the following:

Editing system environment variables in Windows Vista.

Click on ‘Edit the system environment variables’, a dialog box will pop up. Click on ‘Environment Variables…’, you should be greeted with the following dialog box:

Editing the path for environment variables

My path looks like this before I add anything:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

Append these two directories at the back of what is already there:

;C:\Python26\Scripts;C:\Python26

Remember that each directory has to be separated with a semicolon. My Python is installed in ‘C:\Python26′.

2. Installing Django

Extract the Django package that you download to ‘C:\django\’. Use the Command Prompt to navigate to the folder you extract to, in our case, we can type this command:

cd C:\django

Then we have to set up Django:

python setup.py install

And we wait for the the installation to complete. On completion, Django is now fully installed. Let’s try to create an application now to see if it’s working. I created a folder at ‘C:\projects\’ to store all my projects. Once again, we use the Command Prompt to navigate there:

cd C:\projects

Then we create our first Django application:

django-admin.py startproject mysite

Note your C:\projects, it now has an additional folder called ‘mysite’ with the following files:

mysite/
  __init__.py
  manage.py
  settings.py
  urls.py

Okay, let’s try to see if every thing is working fine.

cd C:\projects\mysite

We will start the server now within the ‘mysite’ directory:

python manage.py runserver

The following should appear:

Validating models…
0 errors found.

Django version 0.97-pre-SVN-unknown, using settings ‘mysite.settings’
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Note that the version number is different, depending on what you download. Now go to your browser and type in ‘http://127.0.0.1:8000/’.

Django worked

And it worked! Congratulations on your first Django-powered page.

3. Installing MySQL for Python

Install MySQL for Python as administrator

Once again, I assumed you had MySQL installed already and know how to run and use it.

Run, in administrative mode, the file you just downloaded – MySQL-python-1.2.2.win32-py2.5.exe.

You may run into errors if you do not install as an administrator due to Windows Vista’s security model.

Now, let’s test if the MySQL installation worked. Run the server if it isn’t started. Edit the database setting in ‘mysite/settings.py’.

Update your database information. Save your file. The server will detect a change once you save your file and start to check for errors again. (I personally find this really cool.)

Here’s what I fill in. Your user may not be ‘root’.

DATABASE_ENGINE = ‘mysql’
DATABASE_NAME = ”
DATABASE_USER = ‘root’
DATABASE_PASSWORD = ”
DATABASE_HOST = ”
DATABASE_PORT = ”

If you see no error messages, the database is correctly set up. To do a bit of testing, we can set our user name wrongly on purpose and watch Python throw out the errors then correct it.

Fill in your DATABASE_NAME correctly and we can start coding already. You can continue on the Django tutorial here.

[Forgive me if there're any mistakes in this tutorial and feedback to me.]

27 thoughts on “How to install Python and Django in Windows Vista”

  1. Thanks for posting this – it all just worked!! Looking forward to getting my toes wet now :)

  2. @Jon Sidnell: Have fun!

    @edison chan: It doesn’t require Apache to run actually. Django comes with a built-in web server that makes it so easy to quickly start development. Really cool stuff.

  3. thanks, great job!!
    not sure in this section, but i use this:
    C:\Python25\Lib\site-packages\django\bin\django-admin.py startproject cms
    and works fine for me :)

  4. Hi,
    Thanks so much for the helpful instructions on how to install Django, Python, MySQL.
    I installed them in my new laptop that came with Vista. Everything worked till I tried to edit settings.py file. I kept giving me an error message saying that ‘Access denied for user root@localhost

    Can you think of anything that I may need to change to fix it?

    Thanks,

    Jen

  5. @jen: Hi, it is likely that there are some problems with your MySQL. Could you try to access your MySQL with your ‘root’ user? Is Django the only app that you have trouble with MySQL?

  6. Thanks for this tutorial! I tried following the Django installation guide, but there were a couple of steps/assumptions in their guide that I couldn’t quite sort out, until I read your tutorial.

    You may want to update it to use sqlite3 as the db, as this is included in the latest python versions.

    Thanks again!

  7. im getting “type django-admin.py help” for usage after i run django-admin.py startproject mysite but thats about it. the files do not install to the projects folder ive created on the c

  8. update you have to change the file association from (cant remember) to “%1″ %* and it should work

  9. RE: running the Django development server on Vista, I also had to open up a port on the firewall before this would work. For example I opened up port 8000, for use only by the local machine. This can only be done if you have Administrators rights on VIsta.

  10. im using vista python 2.5 and django 1.1

    I’ve installed django and import django works fine in python interpreter but when i type

    “django-admin startproject mysite”

    a textpad with the following


    #!/usr/bin/env python
    from django.core import management

    if __name__ == “__main__”:
    management.execute_from_command_line()

    pops up, it basically opens up the file django-admin.py how do i fix this.

  11. Nice article. Saved lots of time. And could be nice if you include how to handle the issues when installing mysql-python of version 2.5 on top of existing python 2.6. [ version compatibility]

  12. I was having trouble with the “type django-admin.py help” when starting my project. I am using Vista and found several posts about the problem, but nothing seemed to work. Then I opened regedit and searched for python. I found a few entries that did not have the %* after the “%1″. I changed them and it started working. It seems Vista was not passing the command line variables with the django-admin.py…

  13. Steve Young’s instruction works fine!

    regedit
    find:
    “C:\Python26\python.exe” “%1″
    change to:
    “C:\Python26\python.exe” “%1″ %*

    and this
    “C:\Python26\python26.exe” “%1″
    change to:
    “C:\Python26\python26.exe” “%1″ %*
    (in this case start working)

  14. hi
    i just installed the python, django & mysql-python. now i dont know how to create the mysql database. will you please give me some idea about how to create the database??

    rajesh

  15. It is a great help document. I was struggling on an XP machine to setup the things. InstandDjango another great pointer missed on indicating that Python27 is needed to be loaded via registry for the MySQL-python setup to work. When I visited this page it was all crystal clear to me and I managed to finish the whole setup for python, django, mysqldb all together from scratch within minutes.

    Thanks for sharing this help document.

  16. Nice post..buddy..truly perfect start for a bginner to work through django…Thanks for the info…

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>