2013-02-15 70 views
0

有一個similar question,但在我今天發現的特定情況下沒有應答。UnboundLocalError:分配前引用的本地變量'full_path',同時syncdb

我在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 

回答

2

的錯誤是不漂亮(應該被抓,和完整的錯誤消息應該已返回給用戶),但這種情況發生時,一些默認或可選的串行化模塊中不存在您的系統上。

例如,如果在您的settings.py中,SERIALIZATION_MODULES字典中提到了wadofstuff.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' 
相關問題