python - 执行 python manage.py runserver 时 cmp 错误超出最大递归深度

标签 python django

我正在尝试在我的 Mac 上安装 Django。当我运行命令 python manage.py runserver 时。我收到错误 RuntimeError: maximum recursion depth exceeded in cmp.我在下面粘贴了我的错误消息。我什至将 setrecursion 限制增加到 2000 并尝试过,它没有用。感谢您帮助解决此问题...

验证模型...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1087f4a10>>
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),
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
 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

最佳答案

问题出在 functools.py 文件中。这个文件来自 Python。我刚刚安装了一个新版本的 python 2.7.5 并且文件是错误的(我有另一个较旧的 python 2.7.5 安装并且文件 functools.py 是正确的)

要解决此问题,请替换此(关于 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)]
}

关于python - 执行 python manage.py runserver 时 cmp 错误超出最大递归深度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16369637/

相关文章:

python - pandas dataframe切片产生不同的结果

javascript - Ajax 没有看到文本区域值

python - 更新 Django 中用户对象的变量值

python - 检查Python中的输入和输出文件是否相同

python - numpy.ndarray 枚举适当的维度子集?

python - 在 Ubuntu 16.04 上使用 bazel 从源构建 tensorflow 。错误是 ---> 链接规则 '//tensorflow/contrib/lite/toco:toco' 失败(退出 1)

django - 无法从 Django 小部件的模板获取 MEDIA_URL

python - select_相关链中的顺序

python - 无法访问 Django 中的静态文件 - 开发服务器

python - 为什么快速调用 Python 类的 id 不是唯一的?