I've seen a few posts related to Django, virtualenv and mod_wsgi
however still can't solve my problem.

I keep getting "ImportError: No module named
django.core.handlers.wsgi" in my apache error log no matter what I
try.

Here is the wsgi script:

#### intrack.wsgi ############################################
import os, sys, site

import logging

#create logger
logger = logging.getLogger("intrack_wsgi")

logger.setLevel(logging.DEBUG)

fh = logging.FileHandler("/tmp/InTrackWSGI.log")
fh.setLevel(logging.DEBUG)

formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s
- %(message)s")

fh.setFormatter(formatter)
logger.addHandler(fh)

sys.path.append('/home/intrack/intrack_pythonenv/projects')
sys.path.append('/home/intrack/intrack_pythonenv/projects/InTrack')
os.environ['DJANGO_SETTINGS_MODULE'] = 'InTrack.settings'

ALLDIRS = ['/home/intrack/intrack_pythonenv/lib/python2.5/site-
packages']

# Remember original sys.path.
prev_sys_path = list(sys.path)

# Add each new site-packages directory.
for directory in ALLDIRS:
  site.addsitedir(directory)

# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
    #logger.debug("sys.path item: %s" % item)
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path

logger.debug(sys.path)
logger.debug("exec_prefix: %s" % sys.exec_prefix)
logger.debug("version: %s" % sys.version)

import django.core.handlers.wsgi

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

#### end - intrack.wsgi ############################################

#### apache wsgi.conf
#################################################
WSGIScriptAlias / /var/www/wsgi_scripts/InTrack.wsgi
#### end - apache wsgi.conf
############################################

#### apache error log ############################################
[Wed Apr 15 12:04:29 2009] [error] [client 10.10.0.47] Traceback (most
recent call last):
[Wed Apr 15 12:04:29 2009] [error] [client 10.10.0.47]   File "/var/
www/wsgi_scripts/InTrack.wsgi", line 44, in <module>
[Wed Apr 15 12:04:29 2009] [error] [client 10.10.0.47]     import
django.core.handlers.wsgi
[Wed Apr 15 12:04:29 2009] [error] [client 10.10.0.47] ImportError: No
module named django.core.handlers.wsgi
[Wed Apr 15 12:04:32 2009] [error] [client 10.10.0.47] mod_wsgi
(pid=3610): Target WSGI script '/var/www/wsgi_scripts/InTrack.wsgi'
cannot be loaded as Python module.
[Wed Apr 15 12:04:32 2009] [error] [client 10.10.0.47] mod_wsgi
(pid=3610): Exception occurred processing WSGI script '/var/www/
wsgi_scripts/InTrack.wsgi'.
[Wed Apr 15 12:04:32 2009] [error] [client 10.10.0.47] Traceback (most
recent call last):
[Wed Apr 15 12:04:32 2009] [error] [client 10.10.0.47]   File "/var/
www/wsgi_scripts/InTrack.wsgi", line 44, in <module>
[Wed Apr 15 12:04:32 2009] [error] [client 10.10.0.47]     import
django.core.handlers.wsgi
[Wed Apr 15 12:04:32 2009] [error] [client 10.10.0.47] ImportError: No
module named django.core.handlers.wsgi
#### end - apache error log
############################################

#### wsgi script log ############################################
2009-04-15 12:14:13,938 - intrack_wsgi - DEBUG - ['/home/intrack/
intrack_pythonenv/lib/python2.5/site-packages', '/usr/local/lib/
python25.zip', '/usr/local/lib/python2.5', '/usr/local/lib/python2.5/
plat-linux2', '/usr/local/lib/python2.5/lib-tk', '/usr/local/lib/
python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/
home/intrack/intrack_pythonenv/projects', '/home/intrack/
intrack_pythonenv/projects/InTrack', '/home/intrack/intrack_pythonenv/
projects', '/home/intrack/intrack_pythonenv/projects/InTrack', '/home/
intrack/intrack_pythonenv/lib/python2.5/site-packages']
2009-04-15 12:14:13,939 - intrack_wsgi - DEBUG - exec_prefix: /usr/
local
2009-04-15 12:14:13,939 - intrack_wsgi - DEBUG - version: 2.5.4
(r254:67916, Apr 14 2009, 15:48:34)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)]
#### end - wsgi script log
############################################

I tried this, from the command shell, running the /usr/local/bin/
python (which is the version of python that the wsgi module is running
as per the log above '/usr/local') and then I manually set the
sys.path to:
['/home/intrack/intrack_pythonenv/lib/python2.5/site-packages', '/usr/
local/lib/python25.zip', '/usr/local/lib/python2.5', '/usr/local/lib/
python2.5/plat-linux2', '/usr/local/lib/python2.5/lib-tk', '/usr/local/
lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages',
'/home/intrack/intrack_pythonenv/projects', '/home/intrack/
intrack_pythonenv/projects/InTrack', '/home/intrack/intrack_pythonenv/
projects', '/home/intrack/intrack_pythonenv/projects/InTrack', '/home/
intrack/intrack_pythonenv/lib/python2.5/site-packages']
Exactly as what the log says in the wsgi script that it has the
sys.path set to and guess what? The "import django.core.handlers.wsgi"
works 100%.

So why is it that when wsgi module runs in apache that it doesn't
pickup the django.* when whats in the  sys.path works correctly if ran
manually from interpreter?

I would gladly appreciate if someone could shed some light on this.

Regards,
-Alen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to modwsgi@googlegroups.com
To unsubscribe from this group, send email to 
modwsgi+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to