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

I am trying to use a django application on my local ubuntu machine. However the site doesn't work and my /var/log/apache2/errors.log is filled with messages like this:

ImportError: No module named site

My /var/log/apache2/error.log (for today) looks like this:

$ cat error.log | uniq -c
      1 [Wed Jun 29 09:37:37 2011] [notice] Apache/2.2.17 (Ubuntu) mod_wsgi/3.3 Python/2.7.1+ configured -- resuming normal operations
  12966 ImportError: No module named site

That's the notice that it started up when I turned on my machine, followed by 12,966 lines all saying the no module named site message

note the lack of a datetime field. These errors are repeated even when not going to the website (i.e. even when not making web requests). When going to the website in a browser, it just hangs, as if waiting for a large download.


Apache modules

I am using a python 2.5 virtualenv with lots of packages (incl. django 1.1) installed with pip. I have mod_wsgi loaded:

$ ls -l /etc/apache2/mods-enabled/wsgi*
lrwxrwxrwx 1 root root 27 2010-10-04 16:50 /etc/apache2/mods-enabled/wsgi.conf -> ../mods-available/wsgi.conf
lrwxrwxrwx 1 root root 27 2010-10-04 16:50 /etc/apache2/mods-enabled/wsgi.load -> ../mods-available/wsgi.load

I use "tix" as a domain name that's set to localhost in /etc/hosts

$ grep tix /etc/hosts   tix

Apache config

Here is my apache configuration (You can see some attempts to make it work, commented lines etc.):

# mod-wsgi enabled virtual host
WSGISocketPrefix /home/rory/tix/tix_wsgi/tmp
WSGIPythonHome /home/rory/tix/virtualenv2.5/lib/python2.5/
SetEnv PYTHONPATH /home/rory/tix/virtualenv2.5/lib/python2.5/
#WSGIPythonEggs /home/rory/svn/tix/tmp/python-eggs

    ServerName tix

    Alias /media /home/rory/tix/tix/media
    Alias /selenium /home/rory/tix/tix/tests/selenium

    <Directory /home/rory/tix/tix/media>
        SetHandler None
        Order allow,deny
        Allow from all

    WSGIDaemonProcess tix user=tix_wsgi group=tix_wsgi processes=4 threads=1           python-path=/home/rory/tix/virtualenv2.5/lib/python2.5/site-packages

    WSGIScriptAlias / /home/rory/tix/tix/apache/loader.wsgi
    WSGIProcessGroup tix

    CustomLog /var/log/apache2/tix_access.log combined
    ErrorLog /var/log/apache2/tix_error.log

<Location /server-status>
    SetHandler server-status
    Order Deny,Allow
    Deny from all

  <IfModule rewrite_module>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^media.tix$ [NC]
      RewriteRule .? http://tix/media%{REQUEST_URI} [R=301,L]

wsgi loader

Here is my loader.wsgi:

I used to have import site in this file, which I thought might have caused the problem, but I removed it and the errors keep coming up.

# loader.wsgi - WSGI adapter for tix django project
# The python paste wrapper catches apache 500 errors (Internal Server Errors) and gives debug output
# See
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'tix.settings.base'

from paste.exceptions.errormiddleware import ErrorMiddleware

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

application = ErrorMiddleware(tixette, debug=True, error_email='', error_subject_prefix='Alert: wsgi loader python paste: ', error_log='/tix/1.0/logs/paste.log',  show_exceptions_in_wsgi_errors=False)

This configuration used to work fine on Ubuntu 10.10, but since I upgraded to Ubuntu 11.04, I get the errors above.

share|improve this question
up vote 5 down vote accepted

Your mod_wsgi was compiled for Python 2.7. You cannot then try and point it at a Python 2.5 virtual environment.

Also, the setting:

WSGIPythonHome /home/rory/tix/virtualenv2.5/lib/python2.5/

is pointing at the wrong thing even if it was a Python 2.7 virtual environment.

The settings:

SetEnv PYTHONPATH /home/rory/tix/virtualenv2.5/lib/python2.5/

will not do anything either and don't know where you got the idea you could do that.

FWIW, the mod_wsgi documentation on virtual environments can be found at:

This isn't going to help you though because you seem to have a more basic problem with your mod_wsgi and Python installations to begin with. The issue potentially being a variant of:

Where did you get the you are using?

Where is the Python 2.7 installed?

What other Python versions do you have installed and where?

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.