【问题标题】:Can not execute the makemessages command无法执行 makemessages 命令
【发布时间】:2017-09-20 07:33:01
【问题描述】:

我想使用 i18n,并在我的settings.py 中创建了一个语言环境目录和其他设置。

然后我在我的 PyCharm 中执行python manage.py makemessages -l zh-cn 命令,但失败了。

我的回溯如下:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/management/__init__.py", line 296, in execute
    parser = CommandParser(None, usage="%(prog)s subcommand [options] [args]", add_help=False)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/management/base.py", line 51, in __init__
    super(CommandParser, self).__init__(**kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.py", line 1597, in __init__
    self._positionals = add_group(_('positional arguments'))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 569, in gettext
    return dgettext(_current_domain, message)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 533, in dgettext
    codeset=_localecodesets.get(domain))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 468, in translation
    mofiles = find(domain, localedir, languages, all=1)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 440, in find
    for nelang in _expand_lang(lang):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 133, in _expand_lang
    from locale import normalize
ImportError: cannot import name normalize

【问题讨论】:

    标签: python django django-i18n


    【解决方案1】:

    这是因为你的locale目录下有__init__.py__init__.pyc文件,你应该删除它们。

    右键locale目录->在Finder中显示->就可以看到了,如果只在Pycharm中显示,是看不到.pyc文件的。

    【讨论】:

    • 可能是正确的答案,但在乎解释为什么吗?对 OP 来说可能不是那么明显。
    猜你喜欢
    • 1970-01-01
    • 2020-06-19
    • 2016-08-20
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2021-03-25
    • 1970-01-01
    相关资源
    最近更新 更多