ImportError: No module named django.core.handlers.wsgi in install django mod_wsgi config on apache

I tried to install django to work with apache and mod_wsgi but get this error:

ImportError: No module named django.core.handlers.wsgi,

I'v read that it may be user error...

On the console (ssh), with root access, I don't have any problems accessing django.core.handlers.wsgi , but when apache asks to access it, it can't

My django.wsgi:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'montest.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

My vhost.conf:

Alias /media/ my/rep/parents/of/my/projet/montest/media/

<Directory my/rep/parents/of/my/projet/montest/media>
    Order deny,allow
    Allow from all

WSGIScriptAlias /montest my/rep/parents/of/my/projet/django.wsgi

<Directory my/rep/parents/of/my/projet>
    Order deny,allow
    Allow from all


Ok my result for ldd => (0x0013c000) => /usr/lib/ (0x00663000) => /lib/ (0x00bff000) => /lib/ (0x0023b000) => /lib/ (0x00420000) => /lib/ (0x00110000) => /lib/ (0x00240000) /lib/ (0x0059f000) 

So i decide to test my mod_wsgi install with the test.wsgi


def application(environ, start_response): 
    status = '200 OK'
    output = 'Hello world, I am a wsgi app!' 
    response_headers = [('Content-Type', 'text/plain'), ('Content-Length', str(len(output)))] 
    start_response(status, response_headers) 
    return [output]

my vhost.conf:

WSGIScriptAlias /test /var/www/vhosts/ 
<Directory /var/www/vhosts/> 
    Order allow,deny 
    Allow from all 
    Options +ExecCGI 

It now works... next I will try my django.wsgi config


I solved the problem by adding location of site-packages, where I have kept django subdirectory (/Library/python/2.7/site-packages) to WSGIDaemonProcess:

WSGIDaemonProcess processes=2 threads=15 display-name=%{GROUP} 

If you are using embedded server mode use in httpd.conf:

WSGIPythonPath /Library/python/2.7/site-packages

Why are you even trying to add the site-packages directory into sys.path? If your mod_wsgi is compiled against Python 2.4, then it should already be looking in the site-packages directory. Sounds like your mod_wsgi isn't even compiled against Python 2.4.



against your installed file to work out what Python version it is compiled for and post the result.

I've had this issue before, and it was because the Apache/mod_wsgi process did not have permission to read the modules. You can make your site-packages/django directory world-readable, or add other appropriate user/group permissions.


WSGIDaemonProcess python-path=~/virtualenvs/virt1/lib/python2.7


WSGIDaemonProcess python-path=/home/user/virtualenvs/virt1/lib/python2.7

I spent way too much time trying to figure out why my virtualenv wasn't loading django properly.

I solved this issue by adding the parent directory that holds my django installation to sys.path in Here are my settings, FWIW:


import os, sys
sys.path.append('/home/banjer') # this line solved it
sys.executable = '/usr/local/python-2.7.2/bin/python'
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Check your site-package file permissions. None of the above solutions worked for me until I fix file permissions. Here's what's in my ssl_error_log file:

mod_wsgi (pid=986, process='OSQA', application='|/forum'): Loading WSGI script '/data/http/osqa/osqa.wsgi'. 
mod_wsgi (pid=986): Target WSGI script '/data/http/osqa/osqa.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=986): Exception occurred processing WSGI script '/data/http/osqa/osqa.wsgi'. Traceback (most recent call last):   File "/data/http/osqa/osqa.wsgi", line 14, in <module>
            import django.core.handlers.wsgi  ImportError: No module named django.core.handlers.wsgi

But I solved it on my server. If you can do this on the command line, then this solution is for you:

>>> import django.core.handlers.wsgi

What worked is that I chmod go+rx site-packages libpython* (this might be overkill, but it worked for me.)

I'm running as httpd as apache.user, and running python as root, could see the packages just fine, but my permissions were not setup correctly (to read by everyone), and that's why httpd could not read the packages.

This line is certainly wrong:


Install Django with/for the version of Python that mod_wsgi was built against.

I know this is a somewhat old question, but I thought I'd chime in for future SO users who might find this question:

Your mod_wsgi is linked to python2.6, yet you're using python 2.4 to run django according to your config?

I'm going to assume your /usr/bin/python is pointing to something other than the 2.6 which is what mod_wsgi is compiled against. It might also be due to the fact that you're running django against 2.4. I received the same error when I was loading mod_wsgi linked against python2.6 when django was using python2.7. With the version of mod_wsgi I have installed - it came with support for both python2.[6-7], so all I had to do was remove the symlink in /usr/lib/apache2/modules/ for -> and change it to ->

Easy enough.

It would be a better idea if you remove django from your old python library..

[root@lts5srv1]# rm -rf /root/epd-5.1.0/lib/python2.5/site-packages/django

..and reinstall it inside the 'site-packages' folder of the current python you are using:

[root@lts5srv1 Django-1.4.1]# /usr/local/bin/python2.6 install

That's what i did and i don't get that error anymore!


If you use deb-distributive of Linux (Debian, Ubuntu, etc), edit the file


This file contained path to correct wsgi-library (for active version Python interpreter). If you use Python2.6, change string

LoadModule wsgi_module /usr/lib/apache2/modules/


LoadModule wsgi_module /usr/lib/apache2/modules/

Also, you can change soft link to mod_wsgi module:

cd /usr/lib/apache2/modules
ln -s

Not forget change link to file in /etc/apache2/modules/wsgi.load and restart apache server

service apache2 restart

P.S. Sorry for my bad English

Need Your Help

Java: JSON -> Protobuf & back conversion

java json serialization persistence protocol-buffers

I have an existing system, which is using protobuf-based communication protocol between GUI and server. Now I would like to add some persistence, but at the moment protobuf messages are straight

Add missing dates to pandas dataframe

python date plot pandas dataframe

My data can have multiple events on a given date or NO events on a date. I take these events, get a count by date and plot them. However, when I plot them, my two series don't always match.