4

我正在尝试在我的 Mac 中安装 Django。当我运行命令 python manage.py runserver 时。我收到错误 RuntimeError:在 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
4

6 回答 6

10

问题出在 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)]
}
于 2014-02-17T16:51:36.183 回答
6

如果您还没有,请尝试安装python 2.7.5

我在使用 django 1.5.1 版和 python 2.7.2 版时遇到了类似的问题。当我切换到 2.7.5 时,这个问题得到了解决。

要在您的 Mac 上运行 python 2.7.5,请转到此处并为您的系统下载 Mac 安装程序。安装完成后,进入系统Applications文件夹的“Python 2.7”子文件夹,双击“Update Shell Profile”从命令行使用2.7.5。

之后,python --version从命令行输入以确认您使用的是 2.7.5

希望有帮助!

于 2013-07-31T15:45:22.270 回答
1

在没有任何编码的情况下开始一个新项目后,我遇到了同样的问题。

这里有一个类似的帖子。

就我而言,我只需要卸载然后再次安装 django。

sudo pip uninstall django

sudo pip install django

一个警告。我在新终端中执行了此操作。安装后,我回到出现错误的终端并运行“python manage.py runserver”,我仍然得到同样的错误,但在新的终端窗口上,它没有给我错误。

希望这对你有用。

于 2013-05-04T02:14:22.853 回答
0

确保使用以下命令启动 python shell:

$ python manage.py shell

为了加载正确的设置。我遇到了同样的问题,但我意识到我只是通过使用来启动 shell:

$ python

在 Pavel Anossov 的提交中可以找到对此的一个很好的解释:Django DB Settings 'Improperly Configured' Error

于 2015-04-13T20:16:21.877 回答
0

你运行syncdb了吗?也许尝试使用 sqllite 来确保问题与 mysqldb 包无关?

于 2013-05-04T02:35:42.213 回答
0

我遇到这个错误只是因为我试图在创建新项目后直接运行 migrate 命令。
然后我新建了一个项目,先runserver再运行migrate命令,就可以了。

于 2020-02-02T04:18:42.523 回答