本文介绍了Django的不能导入名称utils的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行Python manage.py的runserver,它工作正常。但是,当我尝试让我的网站通过Apache跑,我不断收到错误:

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"

修改:新的重新安装后追踪Django的

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?

推荐答案

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

Since I'm using an Amazon Linux EC2 Instance, I forgot that installing mod_wsgi from the package installer will be configured using python2.6. So after reinstalling mod_wsgi using python2.7, it fixed my problem.

编辑:

要与 python2.7 配置,在的mod_wsgi 源文件夹中,我做了以下内容:

To configure it with python2.7, inside the mod_wsgi source folder I did the following:

./configure --with-python=/usr/bin/python2.7
make install

这篇关于Django的不能导入名称utils的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 01:26