Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

unsupported locale setting Mac python

I'm trying to change the language of a column week_names from English to Spanish

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you can try to import the locale library first:

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

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:

$ 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/)

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'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...