Python – Apache mod_wsgi error

apache-2.2djangomod-wsgipython

I have followed this guide to setup django on a cpanel server (CentOS 5.2)
http://toic.org/2010/08/14/django-on-cpanel-with-python2-6-virtualenv-and-mod_wsgi/comment-page-1/#comment-680
I get a 500 page on the domain I've set up.

Apache Log:

 File "/home/myofirst/virtualenv/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/handlers/wsgi.py", line 1, in <module>
 File "/home/myofirst/djangosites/test1.wsgi", line 13, in <module>
 mod_wsgi (pid=20251): Exception occurred processing WSGI script '/home/myofirst/djangosites/test1.wsgi'.
 mod_wsgi (pid=20251): Target WSGI script '/home/myofirst/djangosites/test1.wsgi' cannot be loaded as Python module.

WSGI file:

import sys
import site
import os

vepath = '/home/myofirst/virtualenv/lib/python2.6/site-packages'
prev_sys_path = list(sys.path)
site.addsitedir(vepath)
sys.path.append('/home/myofirst/djangosites')
new_sys_path = [p for p in sys.path if p not in prev_sys_path]
for item in new_sys_path:
    sys.path.remove(item)
sys.path[:0] = new_sys_path
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'test1.settings'
application = WSGIHandler()

Seems to be crashing on this line:

from django.core.handlers.wsgi import WSGIHandler

Virtualenv path is correct so I'm not sure what would cause this.

edit I get this traceback when running the .wsgi file.

Traceback (most recent call last):
  File "djangosites/test1.wsgi", line 14, in <module>
    from django.core.handlers.wsgi import WSGIHandler
  File "/home/myofirst/virtualenv/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/handlers/wsgi.py", line 1, in <module>
    from threading import Lock
  File "/opt/python2.6/lib/python2.6/threading.py", line 13, in <module>
    from functools import wraps
ImportError: cannot import name wraps

Best Answer

Is there a __init__.py file in the same folder than test1.wsgi ?

Related Topic