Python语言环境错误:不支持的语言环境设置

在python中执行此操作时为什么会出现以下错误:


>>> import locale

>>> print str( locale.getlocale() )

(None, None)

>>> locale.setlocale(locale.LC_ALL, 'de_DE')

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/lib/python2.7/locale.py", line 531, in setlocale

    return _setlocale(category, locale)

locale.Error: unsupported locale setting

这也适用于其他语言环境,例如fr或nl。我正在使用Ubuntu 11.04。


更新:执行以下操作不会产生任何结果:


dpkg-reconfigure locales

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

    LANGUAGE = (unset),

    LC_ALL = (unset),

    LC_CTYPE = "UTF-8",

    LANG = (unset)

    are supported and installed on your system.

perl: warning: Falling back to the standard locale ("C").

locale: Cannot set LC_CTYPE to default locale: No such file or directory

locale: Cannot set LC_ALL to default locale: No such file or directory


慕姐8265434
浏览 2055回答 3
3回答

梵蒂冈之花

运行以下命令export LC_ALL="en_US.UTF-8"export LC_CTYPE="en_US.UTF-8"sudo dpkg-reconfigure locales它将解决此问题。确保将.UTF-8部分与locale -a例如.utf8在某些系统上的输出中找到的实际语法匹配。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python