It seems you're using Windows. The locale strings are different there. Take a more precise look at the doc:

locale.setlocale(locale.LC_ALL, 'de_DE') # use German locale; name might vary with platform

On Windows, I think it would be something like:

locale.setlocale(locale.LC_ALL, 'deu_deu')

MSDN has a list of language strings and of country/region strings

Answer from Schnouki on Stack Overflow
🌐
Python
docs.python.org › 3 › library › locale.html
locale — Internationalization services
If locale is given and not None, setlocale() modifies the locale setting for the category. The available categories are listed in the data description below. locale may be a string, or a pair, language code and encoding.
🌐
Phrase
phrase.com › home › resources › blog › a beginner’s guide to python’s locale module
A Beginner's Guide to Python's locale Module | Phrase
September 25, 2022 - Let’s have a look at the nuts and bolts of Python’s locale module. Based on the official documentation, the locale module is implemented on top of the _locale module. It uses an ANSI C locale implementation if available. A normal application typically starts with the following code to set the locale: import locale # use user's default settings locale.setlocale(locale.LC_ALL, '') # use current setting locale.setlocale(locale.LC_ALL, None)
Discussions

datetime - Setting Python locale doesn't work - Stack Overflow
If setlocale() hasn't raised locale.Error: unsupported locale setting then the corresponding locale category is set successfully. You could also get the weekday name knowing its position (in the same python session where the locale is changed): More on stackoverflow.com
🌐 stackoverflow.com
Unable to set locale in my python code
Requesting for help as I'm not sure how to add en_IN to the locale on my azure app and then use it in my Python code. More on learn.microsoft.com
🌐 learn.microsoft.com
3
0
July 8, 2021
Python - How to set French locale? - Stack Overflow
ELSE Evaluate locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') locale ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Domain expertise still wanted: the latest trends in AI-assisted knowledge for... ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... 94 What is the correct way to set Python... More on stackoverflow.com
🌐 stackoverflow.com
Rhino 8 - Importing Python 3 Libraries
Hi, I am having a problem importing python libraries (e.g. pandas) into the script editor. Importing libraries produces the following error: Traceback (most recent call last): File "file:///C:/Users/tdowse/.rhinocode… More on discourse.mcneel.com
🌐 discourse.mcneel.com
1
0
March 18, 2024
🌐
Tutorialspoint
tutorialspoint.com › home › python › python setlocale function
Python locale.setlocale() Function
April 13, 2025 - The Python locale.setlocale() function is used to set the locale for the current program.
🌐
Real Python
realpython.com › ref › stdlib › locale
locale | Python Standard Library – Real Python
The Python locale module provides tools to handle the localization of programs, such as formatting numbers, dates, and currencies according to the conventions of different locales.
Top answer
1 of 1
9

It seems like nothing is saved. Am I wrong in assuming you set your locale once and then the system will remember this

yes, calling locale.setlocale() in Python does not affect future python processes. Configure environment variables instead, see How to set all locale settings in Ubuntu.

Bash's "date" method seems to pick up the locale some way or the other.

date calls setlocale(LC_ALL, "") at the start i.e., you need to call setlocale() at least once per process to enable $LANG locale instead of C locale.


setlocale(LC_ALL, '') sets locale according to $LANG variable first, not $LANGUAGE (it is related but different: "The GNU gettext search path contains 'LC_ALL', 'LC_CTYPE', 'LANG' and 'LANGUAGE', in that order.").

It is enough to set LC_TIME category (on Ubuntu):

>>> import locale
>>> import time
>>> time.strftime('%A')
'Tuesday'
>>> locale.getlocale(locale.LC_TIME)
('en_US', 'UTF-8')
>>> locale.setlocale(locale.LC_TIME, 'ru_RU.UTF-8')
'ru_RU.UTF-8'
>>> time.strftime('%A')
'Вторник'
>>> locale.getlocale(locale.LC_TIME)
('ru_RU', 'UTF-8')

If setlocale() hasn't raised locale.Error: unsupported locale setting then the corresponding locale category is set successfully.

You could also get the weekday name knowing its position (in the same python session where the locale is changed):

>>> import calendar
>>> calendar.day_name[1]
'Вторник'
>>> locale.nl_langinfo(locale.DAY_3)
'Вторник'

A portable way, to print a weekday in a given locale without modifying a global state, is to use babel module:

>>> from datetime import date
>>> from babel.dates import format_date # $ pip install babel
>>> format_date(date.today(), format='EEEE', locale='en')
'Tuesday'
>>> format_date(date.today(), format='EEEE', locale='ru')
'вторник'
>>> format_date(date.today(), format='EEEE', locale='nl')
'dinsdag'
🌐
Vstinner
vstinner.github.io › python3-locales-encodings.html
Python 3, locales and encodings — Victor Stinner blog 3
September 6, 2018 - While testing my changes on Windows, I noticed that Python starts with the LC_CTYPE locale equal to "C", whereas locale.setlocale(locale.LC_CTYPE, "") changes the LC_CTYPE locale to something like English_United States.1252 (English with the code page 1252).
🌐
Python Module of the Week
pymotw.com › 3 › locale
locale — Cultural Localization API
December 9, 2018 - import locale sample_locales = [ ('USA', 'en_US'), ('France', 'fr_FR'), ('Spain', 'es_ES'), ('Portugal', 'pt_PT'), ('Poland', 'pl_PL'), ] print('{:>10} {:>10} {:>15}'.format( 'Locale', 'Integer', 'Float') ) for name, loc in sample_locales: locale.setlocale(locale.LC_ALL, loc) print('{:>10}'.format(name), end=' ') print(locale.format_string('d', 123456, grouping=True), end=' ') print(locale.format_string('.2f', 123456.78, grouping=True)) To format numbers without the currency symbol, use format_string() instead of currency(). $ python3 locale_grouping.py Locale Integer Float USA 123,456 123,456.78 France 123456 123456,78 Spain 123456 123456,78 Portugal 123456 123456,78 Poland 123 456 123 456,78
Find elsewhere
🌐
Python
docs.python.org › 3.10 › library › locale.html
locale — Internationalization services — Python 3.10.17 documentation
If locale is given and not None, setlocale() modifies the locale setting for the category. The available categories are listed in the data description below. locale may be a string, or an iterable of two strings (language code and encoding). If it’s an iterable, it’s converted to a locale ...
🌐
Squash
squash.io › complete-guide-how-to-use-python-locale
How to Use Python with Multiple Languages (Locale Guide)
November 23, 2023 - In Python, the locale module provides functionalities to handle various locale-related tasks. It allows developers to format numbers, dates, times, currencies, and sort data based on different cultural conventions. import locale # Set the locale ...
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › locale.setlocale.html
locale.setlocale() — Python Standard Library
locale.setlocale() View page source · locale.setlocale(category, locale=None)[source]¶ · Set the locale for the given category. The locale can be a string, an iterable of two strings (language code and encoding), or None. Iterables are converted to strings using the locale aliasing engine.
🌐
Python
docs.python.org › 3.8 › library › locale.html
locale — Internationalization services — Python 3.8.20 documentation
If locale is given and not None, setlocale() modifies the locale setting for the category. The available categories are listed in the data description below. locale may be a string, or an iterable of two strings (language code and encoding). If it’s an iterable, it’s converted to a locale ...
🌐
Python
svn.python.org › projects › python › trunk › Lib › locale.py
locale.py
Calling setlocale(LC_ALL, "") lets it use the default locale as defined by the LANG variable. Since we don't want to interfere with the current locale setting we thus emulate the behavior in the way described above. To maintain compatibility with other platforms, not only the LANG variable ...
🌐
Python
docs.python.domainunion.de › 3 › library › locale.html
locale — Internationalization services — Python 3.14.3 documentation
This function is similar to getpreferredencoding(False) except this function ignores the Python UTF-8 Mode. Added in version 3.11. ... Returns a normalized locale code for the given locale name. The returned locale code is formatted for use ...
🌐
McNeel Forum
discourse.mcneel.com › scripting
Rhino 8 - Importing Python 3 Libraries - Page 2 - Scripting - McNeel Forum
March 18, 2024 - @Thomas_Dowse In case of en-US, the problem is that it is an invalid locale identifier reported by Windows (en_US being the valid id). In Rhino, when editor is launched I check against this case and a few others and correct them automatically: import locale default_locale, default_codepage = locale.getdefaultlocale() current_locale, current_codepage = locale.getlocale() if default_locale == "en-US" \ or current_locale == "en-US": locale.setlocale(locale.LC_ALL, "en_US") elif '-' in ...
🌐
Tutorialspoint
tutorialspoint.com › python › python_locale_module.htm
Python locale Module
The locale module in Python is used to set and manage cultural conventions for formatting data. It allows programmers to adapt their programs to different languages and regional formatting standards by changing how numbers, dates, and currencies ...