2

If I run python manage.py runserver, it works fine. But when I try to have my site run through apache, I keep getting the error:

 mod_wsgi (pid=25005): Exception occurred processing WSGI script '/apps/peer-web/peer_web/wsgi.py'.
 Traceback (most recent call last):
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
     self.load_middleware()
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 53, in load_middleware
     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
 ImproperlyConfigured: Error importing middleware django.contrib.auth.middleware: "datetime initialization failed"
 mod_wsgi (pid=25005): Exception occurred processing WSGI script '/apps/peer-web/peer_web/wsgi.py'.
 Traceback (most recent call last):
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
     self.load_middleware()
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 53, in load_middleware
     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
 ImproperlyConfigured: Error importing middleware django.contrib.auth.middleware: "cannot import name utils"

EDIT: new traceback after re-installing Django

 mod_wsgi (pid=25005): Exception occurred processing WSGI script '/apps/peer-web/peer_web/wsgi.py'.
 Traceback (most recent call last):
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
     self.load_middleware()
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 53, in load_middleware
     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
 ImproperlyConfigured: Error importing middleware django.contrib.auth.middleware: "cannot import name utils"
 mod_wsgi (pid=25005): Exception occurred processing WSGI script '/apps/peer-web/peer_web/wsgi.py'.
 Traceback (most recent call last):
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
     self.load_middleware()
   File "/apps/peer-web-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 53, in load_middleware
     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
 ImproperlyConfigured: Error importing middleware django.contrib.auth.middleware: "cannot import name utils"

How do I fix this?

4

2 回答 2

4

由于我使用的是 Amazon Linux EC2 实例,我忘记了mod_wsgi从包安装程序安装将使用python2.6. 因此,mod_wsgi使用重新安装后python2.7,它解决了我的问题。

编辑:

要使用 配置它python2.7,在mod_wsgi源文件夹中我执行了以下操作:

./configure --with-python=/usr/bin/python2.7
make install
于 2013-08-04T15:16:15.713 回答
0

请确保将虚拟环境的项目路径和站点包都添加到您的 mod_wsgi 配置中。

WSGIPythonPath /path/to/mysite.com:/path/to/your/venv/lib/python2.X/site-packages

使用 mod_wsgi 和 virtualenv 进行部署的 Django 文档

于 2013-08-04T07:20:56.930 回答