0

有一个类似的问题,但在我今天发现的特定情况下没有回答。

我在 openSUSE 上运行,并且在执行 syncdb 时遇到了这个神秘的错误。我发布我的发现以帮助处于类似情况的其他人。

> python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",     line 459, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",     line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 164, in handle_noargs
    call_command('loaddata', 'initial_data', verbosity=verbosity, database=db)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 150, in call_command
    return klass.execute(*args, **defaults)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 239, in handle
    (full_path, ''.join(traceback.format_exception(sys.exc_type,
UnboundLocalError: local variable 'full_path' referenced before assignment
4

1 回答 1

2

错误不是很漂亮(应该已经被捕获,并且应该向用户返回完整的错误消息),但是当您的系统上不存在某些默认或可选的序列化模块时会发生这种情况。

例如,如果在您的 settings.py 中,在SERIALIZATION_MODULESdictwadofstuff.django.serializers.json中提到了序列化模块,并且没有安装它,它将返回该错误。

安装它,例如:

pip install wadofstuff-django-serializers

在 openSUSE 上,另一种可能是python-xml模块没有安装(它不是python-base包的一部分),因此导入可能会xml.sax.saxutils失败。

在这种情况下,请安装python-xml,例如通过执行以下操作:

sudo zypper in python-xml

它应该可以工作。

如果这不起作用,您可以运行pdb以在它失败的地方放置一个断点。例如:

> python -m pdb manage.py syncdb
> manage.py(2)<module>() -> from django.core.management import execute_manager
(Pdb) b /usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py:110
Breakpoint 1 at /usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py:110
(Pdb) c
Creating tables ...
Installing custom SQL ...
Installing indexes ...
> /usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py(110)handle()
-> for fixture_label in fixture_labels:
(Pdb) n
> /usr/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py(111)handle()
-> parts = fixture_label.split('.')

在某些时候,您会发现错误明显弹出:

ImportError: 'No module named xml.sax.saxutils'
于 2013-02-15T08:48:26.960 回答