简体   繁体   English

不支持的语言环境设置 Mac python

[英]unsupported locale setting Mac python

I'm trying to change the language of a column week_names from English to Spanish我正在尝试将week_names列的语言从英语更改为西班牙语

This is the code:这是代码:

dias_semana=pd.to_datetime(fechas['Fecha'], format='%Y/%m/%d').dt.day_name(locale= "Spanish")
dias_semana=pd.DataFrame(dias_semana)

and the error is this:错误是这样的:

Error: unsupported locale setting

I'm running python in Jupyter notebook, Mac OS Big Sur 11.1.我在 Jupyter 笔记本 Mac OS Big Sur 11.1 中运行 python。

I think you can try to import the locale library first:我认为您可以尝试先导入locale库:

import locale

locale.setlocale(category=locale.LC_ALL,
                 locale="German"  # Note: do not use "de_DE" as it doesn't work)

In your case, you would replace German by Spanish在您的情况下,您将用Spanish替换German

You also might have some luck with:你也可能有一些运气:

try:
    import locale
    locale.setlocale(locale.LC_ALL, 'en_US.utf8')
except Exception:
    try:
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
    except Exception as e:
        messages.error(request, 'An error occurred: {0}'.format(e))

It is also possible to set LC_ALL in your environment by running the following command:也可以通过运行以下命令在您的环境中设置 LC_ALL:

$ export LC_ALL=C

If that doesn't help, then you can try to install dpkg using sudo port install dpkg or brew ( http://macappstore.org/dpkg/ )如果这没有帮助,那么您可以尝试使用sudo port install dpkgbrew安装 dpkg ( http://macappstore.org/dpkg/ )

And then the following:然后是以下内容:

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

For your case, I believe the locale would be 'es_ES.UTF-8'对于您的情况,我相信语言环境将是'es_ES.UTF-8'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM