No module named os found -- Django, mod_wsgi, Apache 2.2
Question: I'm trying to set up apache, mod_wsgi, and django. I'm getting an internal
server error with this in my apache error log:

    
    
    [Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Target WSGI script '/django/internal/django-development.wsgi' cannot be loaded as Python module.
    [Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Exception occurred processing WSGI script '/django/internal/django-development.wsgi'.
    [Wed Jun 22 21:31:55 2011] [error] Traceback (most recent call last):
    [Wed Jun 22 21:31:55 2011] [error]   File "/django/internal/django-development.wsgi", line 3, in <module>
    [Wed Jun 22 21:31:55 2011] [error]     import sys, os
    [Wed Jun 22 21:31:55 2011] [error] ImportError: No module named os
    [Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Target WSGI script '/django/internal/django-development.wsgi' cannot be loaded as Python module.
    [Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Exception occurred processing WSGI script '/django/internal/django-development.wsgi'.
    [Wed Jun 22 21:31:55 2011] [error] Traceback (most recent call last):
    [Wed Jun 22 21:31:55 2011] [error]   File "/django/internal/django-development.wsgi", line 3, in <module>
    [Wed Jun 22 21:31:55 2011] [error]     import sys, os
    [Wed Jun 22 21:31:55 2011] [error] ImportError: No module named os
    

django-development.wsgi

    
    
    #! /usr/bin/env python
    
    import sys, os
    
    path = '/django/internal'
    if path not in sys.path:
        sys.path.append(path)
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'internal.settings'
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

Please let me know if there's anything (configuration files, for example) I
can post to help you help me diagnose this problem.

_edit:_

this is odd, considering I thought I set my default python version to 2.5..,
and ran ./configure with the python2.5 as a parameter

    
    
    $otool -L mod_wsgi.somod_wsgi.so:
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
        /System/Library/Frameworks/Python.framework/Versions/2.6/Python (compatibility version 2.6.0, current version 2.6.1)
    

and

    
    
    LoadModule wsgi_module libexec/apache2/mod_wsgi.so
    WSGIScriptAlias / /django/internal/django-development.wsgi
    

_edit:_

Ah, it looks like a bad configuration file was being imported. I've gotten it
to now give me the following output. Progress:

    
    
    [Wed Jun 22 23:04:28 2011] [error] Exception ImportError: 'No module named atexit' in 'garbage collection' ignored
    Fatal Python error: unexpected exception during garbage collection
    [Wed Jun 22 23:04:28 2011] [error] Exception ImportError: 'No module named atexit' in 'garbage collection' ignored
    Fatal Python error: unexpected exception during garbage collection
    [Wed Jun 22 23:04:29 2011] [notice] caught SIGTERM, shutting down
    [Wed Jun 22 23:04:29 2011] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
    [Wed Jun 22 23:04:29 2011] [warn] mod_wsgi: Compiled for Python/2.5.4.
    [Wed Jun 22 23:04:29 2011] [warn] mod_wsgi: Runtime using Python/2.6.1.
    [Wed Jun 22 23:04:29 2011] [notice] Digest: generating secret for digest authentication ...
    [Wed Jun 22 23:04:29 2011] [notice] Digest: done
    [Wed Jun 22 23:04:29 2011] [notice] Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8l DAV/2 mod_wsgi/3.3 Python/2.6.1 configured -- resuming normal operations
    [Wed Jun 22 23:06:04 2011] [error] [client ::1] client denied by server configuration: /django/internal/django-development.wsgi
    

_edit_

So, I'd still like to figure out how to make mod_wsgi run python 2.5 instead
of 2.6 -- this is what's causing me my big issues right now. Beyond that, it
should just be tweaking the apache configuration.


Answer: mod_wsgi for some reason cannot see your Py2.5 library. I would suggest
checking the value of
[WSGIPythonPath](http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonPath)
and make sure it points to something like /usr/lib/python2.5

