我正在尝试学习Django,这是Django项目网站上的第一个教程。我可能会遗漏一些明显的东西,但是在我按照所有说明运行命令后
python manage.py runserver
我在此请求结束时发布了错误以寻求帮助(为简洁起见,我只发布了错误消息重复行的前几行)。
以下是我在网上找到的一些解决方案/建议,但对我没有帮助。
1)sys.setrecursionlimit(1500)。
这对我不起作用。
2)。Django RuntimeError: maximum recursion depth exceeded
这也不是一个选项,因为我没有使用PyDeV,我尝试使用pip卸载和安装Django它没有修复任何东西我使用Mountain Lion的本机python,我不打算卸载,因为它不推荐。
3)。我也尝试过:
python manage.py runserver --settings=mysite.settings
与没有选项设置的命令相同的错误
任何建议,建议都将不胜感激。 我在用.... Django官方版。 1.5.1我用pip和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
更新: 所以我最终做的就是安装虚拟机,在上面安装免费的ubuntu,然后继续完成教程......太好了!
答案 0 :(得分:39)
问题出在 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)]
}
另请阅读:http://regebro.wordpress.com/2010/12/13/python-implementing-rich-comparison-the-correct-way/
答案 1 :(得分:2)
你可能遇到过这个错误:http://bugs.python.org/issue10042
在没有调试的情况下,究竟发生了什么事情很难说,我想其中一个应该是一个字段的东西不在这一行:
self.local_fields.insert(bisect(self.local_fields, field), field)
答案 2 :(得分:2)
今天我遇到了这个问题。
我们也在使用django1.5.1和python2.7.2。
起初我们安装了django1.4并且它工作正常,但该项目具有django1.5功能,因此它不是一个完整的解决方案。
为了解决这个问题,我们安装了python2.7.5
,它运行良好!
答案 3 :(得分:0)
使用这个: python manage.py migrate