2013-03-06 81 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,並且工作完美無瑕。希望這對你們中的一些人是一種選擇。

相關問題