Ask Your Question

Installation under Apache/mod_wsgi: "ImportError: No module named site"

asked 2012-03-12 10:27:39 -0600

Near the soul's avatar

updated 2012-03-12 19:43:48 -0600

I try to setting apache webserver for running askbot in my local machine but i get this error in /var/log/httpd/error_log:

[Mon Mar 12 16:21:24 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Mon Mar 12 16:21:24 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Mar 12 16:21:24 2012] [notice] Digest: generating secret for digest authentication ...
[Mon Mar 12 16:21:24 2012] [notice] Digest: done
[Mon Mar 12 16:21:25 2012] [notice] Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0g DAV/2 mod_wsgi/3.3 Python/2.7.2 configured -- resuming normal operations
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site

This is my configuration for apache

#NOTE: the directory paths used here may be adjusted

#the following two directories must be both readable and writable by apache
WSGISocketPrefix /var/run/wsgi
#WSGIPythonEggs /usr/lib/python2.7/site-packages/

#the following directory must be readable by apache
WSGIPythonHome /usr/lib/python2.7

#NOTE: all urs below will need to be adjusted if
#settings.FORUM_SCRIPT_ALIAS is anything other than empty string (e.g. = 'forum/')
#this allows "rooting" forum at, if you like

#replace with with real IP address
    DocumentRoot /home/relax/Temp/askmath/
    ServerName example.come

    #aliases to serve static media directly
    #will probably need adjustment
    Alias /static/ /home/relax/Temp/askmath/static/
    Alias /upfiles/ /home/relax/Temp/askmath/askbot/upfiles/
    <DirectoryMatch "/home/relax/Temp/askmath/askbot/skins/([^/]+)/media">
    Order deny,allow
    Allow from all
    <Directory "/home/relax/Temp/askmath/askbot/upfiles">
    Order deny,allow
    Allow from all
    #must be a distinct name within your apache configuration
    WSGIDaemonProcess askbot2
    WSGIProcessGroup askbot2
    WSGIScriptAlias / /home/relax/Temp/askmath/django.wsgi
    #make all admin stuff except media go through secure connection
    <LocationMatch "/admin(?!/media)">
    RewriteEngine on
    RewriteRule /admin(.*)$$1 [L,R=301]
    CustomLog /home/relax/Temp/askmath/log/access_log common
    ErrorLog /home/relax/Temp/askmath/log/error_log
    LogLevel debug
#again, replace the IP address
    DocumentRoot /home/relax/Temp/askmath
    <LocationMatch "^(?!/admin)">
    RewriteEngine on
    RewriteRule django.wsgi(.*)$$1 [L,R=301]
    SSLEngine on
    #your SSL keys
    SSLCertificateFile /etc/httpd/conf/server.crt
    SSLCertificateKeyFile /etc/httpd/conf/server.key
    Alias /admin/media/ /usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/contrib/admin/media
    WSGIScriptAlias / /home/relax/Temp/askmath/django.wsgi
    CustomLog /home/relax/Temp/askmath/log/access_log common
    ErrorLog /home/relax/Temp/askmath/log/error_log


import sys

at the end of the django.wsgi and running "python2 django.wsgi" i get this paths

/home/relax/Temp ...
edit retag flag offensive close merge delete


There isn't any problem with the apache config file (aside from assuring that every path exists and the effective user of apache server has access to them). I would check what the paths (the contents of sys.path) are inside the /home/relax/Temp/askmath/django.wsgi

Evgeny's avatar Evgeny  ( 2012-03-12 19:06:08 -0600 )edit

I add a debugging statements into the wsgi script and run it with python. I list all paths in the main question. I hope this can be helpful to find a solution. I'm going crazy ;)

Near the soul's avatar Near the soul  ( 2012-03-12 19:47:00 -0600 )edit

Looks ok. Where does this exception occur? Thats where I would look into the paths, from the information you gave it is not clear in which file the error is thrown. Usually, when the exception like the one you mentioned in the title happens there is a file name and the line number where that happened. Can you clarify?

Evgeny's avatar Evgeny  ( 2012-03-12 19:50:39 -0600 )edit

I don't know :(! i simply copy the log. Anyway change WSGIPythonHome to /usr and adding <Directory "/home/relax/Temp/askmath/"> Order allow,deny Allow from all </Directory> after WSGIScriptAlias / /home/relax/Temp/askmath/django.wsgi resolve partially the problem ;). Now i can see the site on my browser but without static content (css, image, etc). Any suggestion? Thanks

Near the soul's avatar Near the soul  ( 2012-03-12 21:08:09 -0600 )edit

Ok, much better for static files you need to run in the beginning python collectstatic from the project directory.

Evgeny's avatar Evgeny  ( 2012-03-12 21:21:17 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-03-12 10:43:56 -0600

Evgeny's avatar

updated 2012-03-12 12:35:08 -0600

Possibly this will help you

It is likely that mod_wsgi was compiled for a different version of python intepreter.

You can verify that by finding the file and typing ldd - you'll see the list of libraries linked to the apache module.

It might be helpful to stick some debugging statements into the wsgi script, for example:

import sys

If you notice that there are paths to an unrelated python version - that would indicate the diagnosys I mentioned.

edit flag offensive delete link more


Seems that mod_wsgi works well because i try the test at and everything works fine. Where can i put the statements you mentioned?

Near the soul's avatar Near the soul  ( 2012-03-12 16:23:01 -0600 )edit

the debugging statements would go to file django.wsgi - still it is possible that your mod_wsgi is compiled to work with python 3, or some other than that you've installed for django.

Evgeny's avatar Evgeny  ( 2012-03-12 16:41:51 -0600 )edit

To be clear - maybe mod_wsgi works well but only with the version of python it has been compiled with.

Evgeny's avatar Evgeny  ( 2012-03-12 17:10:40 -0600 )edit

@Katy23 - are you also on archlinux together with @Near the soul? Please try the second trick, insert the sys.stderr.write... statement into the django.wsgi script and read the error logs. When you edit the wsgi script, restart the server just in case - auto-reload works only in daemon mode of mod_wsgi.

Evgeny's avatar Evgeny  ( 2012-03-12 17:22:54 -0600 )edit

Yes i'm with @Near the soul on the same machine. We try the second trick but we don't know where read the error log :( ... anyway i can confirm that the mod_wsgi is compiled for the right python version (2.7)

Katy23's avatar Katy23  ( 2012-03-12 17:33:55 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-03-12 10:27:39 -0600

Seen: 17,298 times

Last updated: Mar 12 '12