Django RuntimeError:超出最大递归深度

时间:2013-03-06 00:02:36

标签: python django eclipse pydev

我是Django的新手。我使用easy_install(在Mac上)和PyDev Django插件为eclipse安装了Django。我按照标准程序创建了一个新的PyDev Django项目。当我尝试以PyDev:Django运行项目时,我收到以下错误。

Validating models...

RuntimeError: maximum recursion depth exceeded

我还尝试在manage.py中添加以下行,但这没用。

sys.setrecursionlimit(2000)

这是部分堆栈跟踪。

Unhandled exception in thread started by <bound method Command.inner_run of    <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10e2*****>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/core/management/commands/runserver.py", line 92, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/core/management/base.py", line 280, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/contrib/auth/models.py", line 370, in <module>
class AbstractUser(AbstractBaseUser, PermissionsMixin):
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/base.py", line 213, in __new__
new_class.add_to_class(field.name, copy.deepcopy(field))
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/base.py", line 265, in add_to_class
value.contribute_to_class(cls, name)
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/fields/__init__.py", line 257, in contribute_to_class
cls._meta.add_field(self)
File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/options.py", line 179, in add_field
self.local_fields.insert(bisect(self.local_fields, field), field)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),

我做错了什么?

3 个答案:

答案 0 :(得分:24)

问题出在functools.py文件中。该文件来自Python。

要解决此问题,请将其替换为(关于python \ Lib \ fuctools.py中的第56行):

    convert = {
    '__lt__': [('__gt__', lambda self, other: other < self),
               ('__le__', lambda self, other: not other < self),
               ('__ge__', lambda self, other: not self < other)],
    '__le__': [('__ge__', lambda self, other: other <= self),
               ('__lt__', lambda self, other: not other <= self),
               ('__gt__', lambda self, other: not self <= other)],
    '__gt__': [('__lt__', lambda self, other: other > self),
               ('__ge__', lambda self, other: not other > self),
               ('__le__', lambda self, other: not self > other)],
    '__ge__': [('__le__', lambda self, other: other >= self),
               ('__gt__', lambda self, other: not other >= self),
               ('__lt__', lambda self, other: not self >= other)]
}

到那个:

    convert = {
    '__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
               ('__le__', lambda self, other: self < other or self == other),
               ('__ge__', lambda self, other: not self < other)],
    '__le__': [('__ge__', lambda self, other: not self <= other or self == other),
               ('__lt__', lambda self, other: self <= other and not self == other),
               ('__gt__', lambda self, other: not self <= other)],
    '__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
               ('__ge__', lambda self, other: self > other or self == other),
               ('__le__', lambda self, other: not self > other)],
    '__ge__': [('__le__', lambda self, other: (not self >= other) or self == other),
               ('__gt__', lambda self, other: self >= other and not self == other),
               ('__lt__', lambda self, other: not self >= other)]
}

另请阅读:http://regebro.wordpress.com/2010/12/13/python-implementing-rich-comparison-the-correct-way/

答案 1 :(得分:0)

我删除了PyDev,Django和Python并重新安装了所有这些,现在它可以工作了。谢谢!

答案 2 :(得分:0)

我在使用pyenv virtualenvs和python 2.7.1时遇到过这种情况。我不想编辑核心文件,所以我升级到2.7.5并且它完美无缺。希望这对你们中的一些人来说是个选择。