Sunday, November 09, 2008

XAMPP + Python + Django

In this post I go over the steps to install XAMPP, Python, and then Django on a Windows XP system. I have also listed the sites that helped me create the setup in my Windows XP machine.

Here are the steps I followed to setup the Django web framework on my Windows XP machine. Lets start with prerequisites,
STEP 1: Prerequisites

  1. Windows XP with Administrative Privilege

  2. XAMPP Windows 1.6.8 [Basic package]

  3. Python 2.5.2 (NOT 2.6, explanation later)

  4. mod_python (mod_python-3.3.1.win32-py2.5-Apache2.2.exe)

  5. Django 1.0 (Django-1.0.tar.gz)
At the end of this step you should have the following files in a folder,
Step 2: Install XAMPP first
Download XAMPP and double click on xampp-win32-1.6.8-installer.exe to start the installation. Just click on next and follow the default settings to have XAMPP installed on your machine. After the installation is complete you will have a directory structure like this,
Double click on xampp-control.exe to start the XAMPP control panel.

Here you can see the status of the Servers. You can start the apache server and check to see whether the web server is running or not.

There are lot of videos available on YouTube that can also help you with installing XAMPP. Here is one such video.

Step 3: Install Python 2.5.2 next
Install Python 2.5.2 (NOT 2.6) as mod_python does not support the Python 2.6 yet. Check out this video for one such installation of Python. This installation also covers installation of mod_python.

Python should be installed in the following directory
Step 4: Install mod_python
Install mod_python by downloading from here mod_python-3.3.1.win32-py2.5-Apache2.2.exe. During installation you have to specify the directory where Apache is installed choose,
Step 5: Install Django 1.0
Download Django-1.0.tar.gz and unzip it. You will see a directory structure as below,
The folder that is of importance is django. Copy the django folder to the following folder,
After you copy the django folder there the folder structure will look like this,
Now copy the file from
to the following two folders,
Now you are all set to test Django on XAMPP.

Step 6: Test Django on XAMPP/Apache
Open the command window and go to the htdocs folder and execute the following command (ref 1),
C:\xampp\htdocs\ startproject testproject
This will create the basic testproject that you can access from local website. But before you can access this you have to open httpd.conf file from the following location,
and then type the following text to the end of the httpd.conf file.

After you type this text please restart the apache webserver. Now visit the following website to see Django in action,
If everything goes alright you will see the following screen,
  1. Django on Windows, this article is very well explained, please go through it.

  2. See also: Django Best Practices

  3. A three-page PDF of Django’s architecture


sridhar said...

I have tried installing but not able to start apache service....

Jyotirmaya said...

If you can not start Apache then please make sure IIS (or some other webserver) is not already running on your machine. IIS (or other webserver) uses port 80 by default. Apache tries to listen to port 80 and fails to start.

Naoussi said...

Hello, i followed your tutorial but i have a problem, when i add the line LoadModule python module modules/ apache doesn't start again but when i uncomment it, it starts, please where is the problem i don't understang
I download the package you suggest

Jyotirmaya said...

The following two forum discussions may help you troubleshoot the problem with (1) , (2) .

kangghee said...

Three mistakes that I made when following the above instructions:

1. On Windows XP, I forgot to add to the environment settings of "My Computer" for path, to have the extra ";c:\python25;c:\python25\scripts"

2. I needed to add the LoadModule line the htt...conf file.

3. I did not reboot, and the Apache did not manage to start again.

Once all three have been done, everything works fine.


R.Kumar said...

hello sir i have got tht error when i run testproject


ProcessId: 2708
Interpreter: 'localhost'

ServerName: 'localhost'
DocumentRoot: 'D:/xampp/htdocs'

URI: '/testproject/'
Location: '/testproject/'
Directory: None
Filename: 'D:/xampp/htdocs/testproject/'
PathInfo: ''

Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'

Traceback (most recent call last):

File "C:\Python25\Lib\site-packages\mod_python\", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

File "C:\Python25\Lib\site-packages\mod_python\", line 1229, in _process_target
result = _execute_target(config, req, object, arg)

File "C:\Python25\Lib\site-packages\mod_python\", line 1128, in _execute_target
result = object(arg)

File "c:\python25\Lib\site-packages\django\core\handlers\", line 222, in handler
return ModPythonHandler()(req)

File "c:\python25\Lib\site-packages\django\core\handlers\", line 185, in __call__

File "c:\python25\Lib\site-packages\django\core\handlers\", line 31, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:

File "c:\python25\Lib\site-packages\django\conf\", line 28, in __getattr__

File "c:\python25\Lib\site-packages\django\conf\", line 59, in _import_settings
self._target = Settings(settings_module)

File "c:\python25\Lib\site-packages\django\conf\", line 94, in __init__
raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)

ImportError: Could not import settings 'testproject.settings' (Is it on sys.path? Does it have syntax errors?): No module named testproject.settings

kangghee said...

Hi Kumar:
Sadly I can't tell from your MOD_Python error messages why it did not work for you. We're assuming you have done all the stuffs in this blog already.

Hariyadi Maramis said...

okay, I also have some problem after I've done all of the step above. My apache service is unable to start again.

Jyotirmaya said...
If you can not start Apache then please make sure IIS (or some other webserver) is not already running on your machine. IIS (or other webserver) uses port 80 by default. Apache tries to listen to port 80 and fails to start.
How do I know that some other webserver is running on my machine. As far as I know, I only let apache XAMPP on it?

Please, could you help me?
Thanks in advance

Jyotirmaya said...

Hariyadi please try the netstat -a -n command at your DOS prompt to see what all ports are occupied. More on netstat command can be found here

Spark said...

Followed every step and, after the additions to the httpd.conf, Apache wasn't starting.

As described in the tutorial:

the line:
LoadModule python_module modules/

needs to be added after all those existing LoadModule lines in the httpd.conf file.

After that Apache was able to start.

Hope it helps.

Cheers, and thanks again for this tutorial.

Mahbub said...

Thanks a lot. That worked like a charm. Now i don't have to switch between windows and ubuntu to do python stuff.

Ashraf said...

I have already successfully change the configuration. Successfully run. Wellcome to django page has load. But I have created the file on this directory and cannot be change the page.

Mahbub said...

After playing with the installation of django on windows, i found web2py. Give it a try. It's even easier and with almost no installation. Check this article as well on web2py

rajmohan said...

I followed all the steps as you told.. First time it works fine for me. After some time I tried to create a new project using startproject mysimpleapplication

but it is not working. It is opening the file in editor instead of creating a new application.
Pls let me know what was the problem.

Seab said...

Has anyone tried this install on Windows 7? I have had XAMPP up and running for a while and Python installed fine. But when I try to install Mod_python it throws an error saying it cannot find Python in the registry and won't let me install. Has anyone gotten around this?

Rubén Ramos said...

Hi !!! I've installed W7 and when I try to install "mod_python" also say like you, but I think that is innocuous because when type a see the Welcome to Django Web Page...

dom said...

thanks for article!!!
this command make directory on C:
C:\xampp\htdocs\ startproject testproject

if You copy the testproject to your directory (eg. C:\x\xampp\htdocs) everthing is ok

LoadModule python_module modules/

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE testproject.settings
PythonOption django.root /testproject
PythonDebug On
#PythonPath "['c:/Python25','c:/wamp/www/testproject/', 'c:/wamp/www', '/django'] + sys.path"
PythonPath "['c:/Python25','c:\python25\scripts','C:/x/xampp/htdocs'] + sys.path"

Satish said...

After I add the <Location.... the XAMPP Apache doesn't restart.

when I remove it it restarts.
Dont seem to know what the problem is.

[ Amuleto ] said...

the line:
LoadModule python_module modules/

needs to be added after all those existing LoadModule lines in the httpd.conf file.

After that Apache will be able to start.

ADi said...

I added the LoadModule at the end of all existing modules but it still don't let Apache start.

(c) Jyotirmaya Nanda 2012