Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my django.wsgi

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
os.environ['PYTHON_EGG_CACHE'] = '/var/www/django/myapp/.python-eggs'

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


    DocumentRoot /var/www/default
    ServerName localhost
    WSGIScriptAlias /myapp /var/www/django/myapp/apache/django.wsgi
    ErrorLog /var/www/django/myapp/logs/error_log

The Apache error says the following

When i go to localhost/myapp then it gives some server error

[Fri Jun 25 12:42:42 2010] [error] [client] File does not exist: /var/www/default/favicon.ico
[Fri Jun 25 12:42:45 2010] [error] [client] File does not exist: /var/www/default/favicon.ico
[Fri Jun 25 12:42:48 2010] [info] [client] mod_wsgi (pid=3585, process='', application='localhost|/myapp'): Loading WSGI script '/var/www/django/myapp/apache/django.wsgi'.
[Fri Jun 25 12:42:48 2010] [error] [client] mod_wsgi (pid=3585): Target WSGI script '/var/www/django/myapp/apache/django.wsgi' cannot be loaded as Python module.
[Fri Jun 25 12:42:48 2010] [error] [client] mod_wsgi (pid=3585): Exception occurred processing WSGI script '/var/www/django/myapp/apache/django.wsgi'.
[Fri Jun 25 12:42:48 2010] [error] [client] Traceback (most recent call last):
[Fri Jun 25 12:42:48 2010] [error] [client]   File "/var/www/django/myapp/apache/django.wsgi", line 8, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client]     import django.core.handlers.wsgi
[Fri Jun 25 12:42:48 2010] [error] [client]   File "/opt/python2.6/lib/python2.6/site-packages/django/core/handlers/", line 1, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client]     from threading import Lock
[Fri Jun 25 12:42:48 2010] [error] [client]   File "/opt/python2.6/lib/python2.6/", line 13, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client]     from functools import wraps
[Fri Jun 25 12:42:48 2010] [error] [client]   File "/opt/python2.6/lib/python2.6/", line 10, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client]     from _functools import partial, reduce
[Fri Jun 25 12:42:48 2010] [error] [client] ImportError: /opt/python2.6/lib/python2.6/lib-dynload/ failed to map segment from shared object: Permission denied

Output of ldd: =>  (0x0098c000) => /usr/lib/ (0x00423000) => /lib/ (0x005cd000) => /lib/ (0x00110000) => /lib/ (0x006d8000) => /lib/ (0x00778000) => /lib/ (0x00a46000)
        /lib/ (0x002e5000)

I tried import sys and there was no error in apace the only line was

[Mon Jun 28 13:33:24 2010] [info] [client] mod_wsgi (pid=19384, process='', application='python.localhost|/application'): Loading WSGI script '/var/www/application/application.wsgi'.
share|improve this question
You cut off the bottom of your error log. – Ignacio Vazquez-Abrams Jun 25 '10 at 2:52
THis is the whole error log in my file – John Jun 25 '10 at 3:13
up vote 0 down vote accepted

What platform? What exact version of Python is installed for the operating system? What exact version of Python is installed in /opt/python2.6? What do you get when you do 'ldd' for installed mod_wsgi Apache module .so file? Are you by chance setting WSGIPythonHome in configuration?

Overall this looks a bit like you might be picking up Python shared libraries or installed Python lib directory for different versions and there is an incompatibility.

Also go back and get a hello world WSGI script working instead of Django and when that works add to it:

import threading

so you can see if you can create a standalone test that can be used to investigate what is happening separate to Django.

For hello world example see:

Finally, for good measure make sure you aren't loading mod_python in the same Apache instance.

share|improve this answer
Platform is CenOS 5 . BY Default the python is 2.4 but i have installed python 2.6 in /opt/python2.6. I have the another virtual host called python.localhost with Docroot /var/www/application and that is working fine. I have created other virual host called LOCALHOST for django and its not showing up. I followed all steps fron ur Google guide and it gives me this error. I am not at all loading mod_python. my django project is in /var/www/django/myapp and wsgi file is in myapp/apache. i added that import threading line in that hello world sript and i get same error . if i remove then it works – John Jun 25 '10 at 7:37
But what does 'ldd' yield? Also in the hello world, now add 'import sys; print >> sys.stderr, sys.prefix, sys.path'. Check Apache error logs for what they are set to. All up though you are better off taking this over to the mod_wsgi mailing list. A prior thread about this issue is at '…;. Not sure though that we really sorted it out and person with issue seemed to vanish with no resolution. – Graham Dumpleton Jun 25 '10 at 10:24
Thanks for your help , i will go to office monday and then i will do that – John Jun 25 '10 at 11:31
I tried that and i have edited the post with new details – John Jun 28 '10 at 4:03

does your webserver have write permissions to /var/www/django/myapp/.python-eggs ?

share|improve this answer
yes its 777 permission – John Jun 25 '10 at 3:29
at the bottom of… is an alternate. The only real difference I see is that you are appending the path, and Graham Dumpleton inserts the path. It looks to me like the path it is trying to include is a system path rather than a virtual environment, so, the script listed at the bottom of that post will probably fix it. – karmawhore Jun 25 '10 at 3:53
i tried that and same error – John Jun 25 '10 at 4:52

It would appear the problem can be solved by disabling SELinux, although not many people would go for that. Another is to try to set the appropriate permissions and contexts to the files trying to be accessed (don't ask me!)

Here ( is a guy who seems to have solved the problem, but I haven't checked it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.