Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: python manage.py runserver gives RuntimeError: maximum recursion depth exceeded in cmp

Tags:

python

django

I am trying to learn Django form the 1st tutorial on the Django project website. I might be missing something obvious but, after following all the instructions when I come to run the command

python manage.py runserver

I get the error posted at the end of this plea for help (I have posted only the first few lines of the repeated lines of the error message for brevity).

Here are some of the solutions/suggestions I have found on the web but were NOT helpful to me.

1)sys.setrecursionlimit(1500).

This didn't work for me.

2).Django RuntimeError: maximum recursion depth exceeded

This also isn't an option because I am not using PyDeV, I tried uninstalling and installing Django using pip it didn't fix anything and I am using Mountain Lion's native python, which I am not going to uninstall, since it is not recommended.

3). I also tried:

 python manage.py runserver --settings=mysite.settings

Same exact error as the command without the option settings

Any suggestions, recommendations would be much appreciated. I am using.... Django Official Version. 1.5.1 which I installed using pip and Python 2.7.2

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10f7ee5d0>>
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/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/core/management/base.py", line 280, in validate
    num_errors = get_validation_errors(s, app)
  File "/Library/Python/2.7/site-packages/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/db/models/loading.py", line 166, in get_app_errors
    self._populate()
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 72, in _populate
    self.load_app(app_name, True)
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py", line 370, in <module>
    class AbstractUser(AbstractBaseUser, PermissionsMixin):
  File "/Library/Python/2.7/site-packages/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/db/models/base.py", line 265, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Library/Python/2.7/site-packages/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/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),
  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),

  RuntimeError: maximum recursion depth exceeded in cmp

UPDATE: So what I ended up doing was to do an overkill of installing virtualbox, installing free ubuntu on it and then moving on to finish the tutorial...oh well!

like image 855
Sason Torosean Avatar asked Apr 28 '13 04:04

Sason Torosean


People also ask

How to Fix maximum recursion depth exceeded in comparison in Python?

The maximum recursion depth in Python is 1000. You can change the limit by calling sys. setrecursionlimit() method.

How to increase max recursion depth in Python?

Using the setrecursionlimit() method, we can increase the recursion limit and the program can be executed without errors even on large inputs.

How to solve recursion error in Python?

The “maximum recursion depth exceeded in comparison” error is raised when you try to execute a function that exceeds Python's built in recursion limit. You can fix this error by rewriting your program to use an iterative approach or by increasing the recursion limit in Python.

Why does Python have a recursion limit?

It's to avoid a stack overflow. The Python interpreter limits the depths of recursion to help you avoid infinite recursions, resulting in stack overflows.


2 Answers

The problem is in functools.py file. This file is from Python. I have just installed a new version of python 2.7.5 and this file is wrong (I have another - older installation of python 2.7.5 and there the file functools.py is correct)

To fix the problem replace this (about line 56 in python\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)]
}

to that:

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)]
}

Read also: http://regebro.wordpress.com/2010/12/13/python-implementing-rich-comparison-the-correct-way/

like image 165
tstempko Avatar answered Oct 06 '22 01:10

tstempko


You have likely run into this bug: http://bugs.python.org/issue10042

Exactly what happens is hard to tell without debugging, bit I'd guess one of the things that should be a field isn't in this line:

self.local_fields.insert(bisect(self.local_fields, field), field)
like image 25
Lennart Regebro Avatar answered Oct 06 '22 01:10

Lennart Regebro