Django haystack 语法错误

Django haystack Syntax error

我正在尝试 运行 一个在我同事的机器上运行良好的 Django 项目,但是当我尝试 运行server.

时我从 haystack 收到一个错误
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python3.2/dist-packages/django/core/management/base.py", line 280, in execute
    translation.activate('en-us')
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/__init__.py", line 130, in activate
    return _trans.activate(language)
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/local/lib/python3.2/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "/usr/lib/python3.2/importlib/__init__.py", line 124, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/lib/python3.2/importlib/_bootstrap.py", line 821, in _gcd_import
    loader.load_module(name)
  File "/usr/lib/python3.2/importlib/_bootstrap.py", line 436, in load_module
    return self._load_module(fullname)
  File "/usr/lib/python3.2/importlib/_bootstrap.py", line 141, in decorated
    return fxn(self, module, *args, **kwargs)
  File "/usr/lib/python3.2/importlib/_bootstrap.py", line 342, in _load_module
    exec(code_object, module.__dict__)
  File "/usr/local/lib/python3.2/dist-packages/haystack/__init__.py", line 7, in <module>
    from haystack.utils import loading
  File "/usr/local/lib/python3.2/dist-packages/haystack/utils/__init__.py", line 28
    raise AttributeError(u"Provided string '%s' is not a valid identifier." % obj_or_string)
                                                                          ^
SyntaxError: invalid syntax

我在你安装的应用程序中包含 haystack。

Linux ubuntu 3.5.0-44-generic #67-Ubuntu SMP 11 月 12 日星期二 19:36:14 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Python 3.2.3

pip 6.0.8 来自 /usr/local/lib/python3.2/dist-packages (python 3.2)

Name: django-haystack
Version: 2.3.1
Location: /usr/local/lib/python3.2/dist-packages
Requires: Django

欢迎提出任何想法

谢谢

这似乎是 Python 版本问题。 Python 3.2 没有字符串的 u 前缀,因为字符串在 Python 3 中默认是 unicode。前缀在 Python 3.3 中重新引入,以便与 2.7 兼容更容易.见 3.3 release notes.

请注意 PyPI page for Haystack 2.3.1 提到 3.3+ 作为要求。

您应该将 Python 版本升级到 3.3。