2013-03-06 159 views
3

我是Django的新手。我使用easy_install(在Mac上)和PyDev Django插件来安装Django,用于eclipse。我遵循标准程序来创建一个新的PyDev Django项目。当我尝试以PyDev:Django的身份运行该项目时,出现以下错误。Django RuntimeError:超过最大递归深度

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), 

我在做什么错?

+0

你确定你的模型没有引用对方或什么奇怪的东西吗? – GordonsBeard 2013-03-06 00:08:39

+0

这只是一个空的项目,并且具有与Django官方网站中指定的相同的结构和内容。 – Ashwin 2013-03-06 00:21:37

+0

您可以请寄出堆栈跟踪吗? – andrefsp 2013-03-06 00:53:39

回答

0

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

24

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

要解决该问题替换这个(关于蟒蛇线56 \ LIB \ fuctools.py):

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/

+0

这解决了Windows 10上的问题,编辑文件C:\ Python27 \ Lib \ functools.py – 2015-12-10 22:24:49

+0

这真的是有用的答案并解决了我的问题,但是您是如何找到错误的原因的 – 2016-04-13 07:27:22

0

我在Python 2.7.1中使用pyenv virtualenvs时遇到了这个问题。我不想编辑核心文件,所以我升级到2.7.5,并且工作完美无瑕。希望这对你们中的一些人是一种选择。

相关问题