python:locale。错误:不支持的区域设置

python:locale。错误:不支持的区域设置,python,ubuntu,utf-8,locale,Python,Ubuntu,Utf 8,Locale,我的代码有: def sep(num, lang='en', none_is_zero=False): if num is None: if none_is_zero is False: return None else: return 0 try: locale.setlocale(locale.LC_ALL, lang) except locale.Error:

我的代码有:

def sep(num, lang='en', none_is_zero=False):
    if num is None:
        if none_is_zero is False:
            return None
        else:
            return 0
    try:
        locale.setlocale(locale.LC_ALL, lang)
    except locale.Error:
        locale.setlocale(locale.LC_ALL, 'en')
    return locale.format("%d", num, grouping=True)
由于我遇到了该错误,我尝试运行此测试:

def test(bot, job):
    print(sep(12343, 'it'))
    print(sep(11425, 'en'))
    print(sep(1234235, None))
    print(sep(42345, ''))
    print(sep(2353636, 'gergreh'))
    print(sep(None, None))
我得到了这个错误:

Traceback (most recent call last):
  File "/home/**/utils.py", line 192, in sep
    locale.setlocale(locale.LC_ALL, lang)
  File "/usr/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/telegram/ext/jobqueue.py", line 286, in tick
    job.run(self.bot)
  File "/usr/local/lib/python3.5/dist-packages/telegram/ext/jobqueue.py", line 411, in run
    self.callback(bot, self)
  File "/home/**/utils.py", line 199, in test
    print(sep(12343, 'it'))
  File "/home/**/utils.py", line 194, in sep
    locale.setlocale(locale.LC_ALL, 'en')
  File "/usr/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
但是我没有在windows上得到任何错误,并且该函数按预期工作。问题只出现在我的ubuntu vps上。 在stackoverflow上找到一些答案时,我看到有人建议使用“en_US.UTF-8”,我尝试了一下,它甚至可以在linux上运行。但是“恩,UTF-8”仍然不起作用。如果需要,我可以附加
UTF-8
,但我使用的api有时只返回langu代码“en”、“it”、“es”


我怎样才能解决这个问题?在windows上,我没有问题,问题似乎只是我的linux vps与
it
en
等有一些相关信息;另请参见该页上的其他答案(及其评论)。谢谢。据我所知,我应该解决执行
locale.setlocale(locale.LC\u ALL,locale.locale\u别名[lang])
我说得对吗@PM2RingI链接到建议使用第三方
babel
模块的答案。该页面上的其他信息表明,
locale.locale\u alias
在Windows上无法正常工作。我解决了使用babel函数对数字进行分组的问题。感谢您可能的副本添加一个简短的描述连同答案是感激的。
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales