I attempted to set up django on my small apache on mod_wsgi ,

I've this error : ImportError: No module named django.core.handlers.wsgi,

I v read, might be it's some user problem...

On console ssh, with root access not a problem to gain access to django.core.handlers.wsgi , however when apache request to gain access to it does not work... i want help Thx

My django.wsgi

import os
import sys

sys.path.append('my/rep/parents/of/my/projet')
sys.path.append('/usr/lib/python2.4/site-packages/django')
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
</Directory>

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

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

My error :

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

EDIT :

Ok my result for ldd mod_wsgi.so

linux-gate.so.1 => (0x0013c000) 
libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0 (0x00663000) 
libpthread.so.0 => /lib/libpthread.so.0 (0x00bff000) 
libdl.so.2 => /lib/libdl.so.2 (0x0023b000) 
libutil.so.1 => /lib/libutil.so.1 (0x00420000) 
libm.so.6 => /lib/libm.so.6 (0x00110000) 
libc.so.6 => /lib/libc.so.6 (0x00240000) /lib/ld-linux.so.2 (0x0059f000) 

And so i choose to test my mod_wsgi install using the test.wsgi

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/mydomain.fr/subdomains/django/httpdocs/test.wsgi 
<Directory /var/www/vhosts/mydomain.fr/subdomains/django/httpdocs> 
Order allow,deny 
Allow from all 
Options +ExecCGI 
</Directory> 

It's work... i tries with my django config

The reason for even attempting to add the website-packages directory into sys.path? In case your mod_wsgi is put together against Python 2.4, it should be searching within the site-packages directory. Seems like your mod_wsgi is not even put together against Python 2.4.

Run:

ldd mod_wsgi.so

against your installed mod_wsgi.so file to sort out what Python version it's put together for and publish the end result.

This lines are certainly wrong:

sys.path.append('/usr/lib/python2.4/site-packages/django')

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

I have had this problem before, also it was since the Apache/mod_wsgi process was without permission to see the modules. You may make your website-packages/django directory world-readable, or add other appropriate user/group permissions.

I understand this can be a somewhat old question, but I decided to chime set for future SO customers who will dsicover this:

Your mod_wsgi is related to python2.6, yet you are using python 2.4 to operate django based on your config?

I am likely to assume your /usr/bin/python is pointing to something apart from the two.6 that is what mod_wsgi is put together against. It could be also because of the truth that you are running django against 2.4. I received exactly the same error after i was loading mod_wsgi linked against python2.6 when django was using python2.7. Using the version of mod_wsgi I've installed - it included support for python2.[6-7], so that all I needed to do was take away the symlink in /usr/lib/apache2/modules/ for mod_wsgi.so -> mod_wsgi.so-2.6 and alter it to mod_wsgi.so -> mod_wsgi.so-2.7.

Simple.