Python语言环境错误:不支持的语言环境设置 [英] Python locale error: unsupported locale setting

查看:967
本文介绍了Python语言环境错误:不支持的语言环境设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why do I get the following error when doing this in 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.

This works with other locales like fr or nl as well. I'm using Ubuntu 11.04.

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

Update: Doing the following did not yield anything:

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

推荐答案

运行以下命令

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales

它将解决此问题.

确保将.UTF-8部分与locale -a输出中找到的实际语法匹配,例如.utf8在某些系统上.

Make sure to match the .UTF-8 part to the actual syntax found in the output of locale -a e.g. .utf8 on some systems.

这篇关于Python语言环境错误:不支持的语言环境设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆