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
On Android or if the Python UTF-8 ... the do_setlocale argument are ignored. The Python preinitialization configures the LC_CTYPE locale. See also the filesystem encoding and error handler. Changed in version 3.7: The function now always returns "utf-8" on Android or if the Python UTF-8 Mode is enabled. ... On Android and VxWorks, return "utf-8". On Unix, return the encoding of the current LC_CTYPE locale. Return "utf-8" if nl_langinfo(CODESET) returns an empty string: for example, if the current ...
🌐
Real Python
realpython.com › ref › stdlib › locale
locale | Python Standard Library – Real Python
>>> import locale >>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8") 'en_US.UTF-8' >>> prices = [19.99, 5.49, 3.75] >>> formatted_prices = [ ... locale.currency(price, grouping=True) for price in prices ...
🌐
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 - 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)
🌐
ProgramCreek
programcreek.com › python › example › 497 › locale.setlocale
Python Examples of locale.setlocale
def activate_locale(self): """ Activates this user's locale """ try: lc = self.locale.split('.') region = self.region.split('.') locale.setlocale(locale.LC_TIME, region) locale.setlocale(locale.LC_MESSAGES, lc) locale.setlocale(locale.LC_NUMERIC, region) locale.setlocale(locale.LC_MONETARY, region) except Exception as e: locale.setlocale(locale.LC_ALL, None) # Return the language code return self.locale.split('_', 1)[0]
🌐
Tutorialspoint
tutorialspoint.com › home › python › python setlocale function
Python locale.setlocale() Function
April 13, 2025 - Following is an example of the Python locale.setlocale() function.
🌐
Python Module of the Week
pymotw.com › 3 › locale
locale — Cultural Localization API
December 9, 2018 - import locale import time sample_locales = [ ('USA', 'en_US'), ('France', 'fr_FR'), ('Spain', 'es_ES'), ('Portugal', 'pt_PT'), ('Poland', 'pl_PL'), ] for name, loc in sample_locales: locale.setlocale(locale.LC_ALL, loc) format = locale.nl_langinfo(locale.D_T_FMT) print('{:>10}: {}'.format(name, time.strftime(format))) This example uses the date formatting string for the locale to print the current date and time. $ python3 locale_date.py USA: Sun Dec 9 12:20:00 2018 France: Dim 9 déc 12:20:00 2018 Spain: dom 9 dic 12:20:00 2018 Portugal: Dom 9 Dez 12:20:00 2018 Poland: ndz 9 gru 12:20:00 2018 ·
🌐
Vstinner
vstinner.github.io › python3-locales-encodings.html
Python 3, locales and encodings — Victor Stinner blog 3
September 6, 2018 - C:\> python Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 >>> import locale >>> locale.setlocale(locale.LC_CTYPE, None) 'C' >>> locale.setlocale(locale.LC_CTYPE, "") 'English_United States.1252' >>> locale.setlocale(locale.LC_CTYPE, None) 'English_United States.1252' On UNIX, Python 2 starts with the default C locale, whereas Python 3 always sets the LC_CTYPE locale to my preference. Example on Fedora 28 with LANG=fr_FR.UTF-8:
Find elsewhere
🌐
Python
docs.python.org › 2.0 › lib › module-locale.html
6.22 locale -- Internationalization services
import locale locale.setlocale(locale.LC_ALL,"") This sets the locale for all categories to the user's default setting (typically specified in the $LANG environment variable).
🌐
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 ...
🌐
Python Module of the Week
pymotw.com › 2 › locale
locale – POSIX cultural localization API - Python Module of the Week
$ export LANG=; export LC_CTYPE=; python locale_env_example.py Environment settings: LC_ALL = LC_CTYPE = LANG = LANGUAGE = Locale from environment: (None, None) Numeric formatting: Decimal point : "." Grouping positions : [] Thousands separator: "" Monetary formatting: International currency symbol : "''" Local currency symbol : '' () Symbol precedes positive value : 127 Symbol precedes negative value : 127 Decimal point : "" Digits in fractional values : 127 Digits in fractional values, international: 127 Grouping positions : [] Thousands separator : "" Positive sign : "" Positive sign position : Unspecified Negative sign : "" Negative sign position : Unspecified
🌐
Python
docs.python.org › 3.7 › library › locale.html
locale — Internationalization services — Python 3.7.17 documentation
There is one exception: the LC_CTYPE category is changed at startup to set the current locale encoding to the user’s preferred locale encoding. The program must explicitly say that it wants the user’s preferred locale settings for other categories by calling setlocale(LC_ALL, '').
🌐
Python
docs.python.org › 3.8 › library › locale.html
locale — Internationalization services — Python 3.8.20 documentation
There is one exception: the LC_CTYPE category is changed at startup to set the current locale encoding to the user’s preferred locale encoding. The program must explicitly say that it wants the user’s preferred locale settings for other categories by calling setlocale(LC_ALL, '').
🌐
Python
docs.python.org › 3.6 › library › locale.html
23.2. locale — Internationalization services — Python 3.6.15 documentation
There is one exception: the LC_CTYPE category is changed at startup to set the current locale encoding to the user’s preferred locale encoding. The program must explicitly say that it wants the user’s preferred locale settings for other categories by calling setlocale(LC_ALL, '').
🌐
Squash
squash.io › complete-guide-how-to-use-python-locale
How to Use Python with Multiple Languages (Locale Guide)
November 23, 2023 - Python provides modules like pytz for working with time zones. By combining the capabilities of the locale module with time zone conversion libraries, you can handle localization and time zone-related tasks effectively. import datetime import pytz # Set the timezone to UTC timezone_utc = pytz.timezone('UTC') # Set the locale to French (France) locale.setlocale(locale.LC_ALL, 'fr_FR') # Get the current date and time in UTC utc_now = datetime.datetime.now(timezone_utc) # Format the UTC date and time using French conventions formatted_datetime = utc_now.strftime("%A %d %B %Y - %H:%M") print(formatted_datetime)
🌐
Lbl
davis.lbl.gov › Manuals › PYTHON-2.4.3 › lib › module-locale.html
6.27 locale -- Internationalization services
March 29, 2006 - >>> import locale >>> loc = locale.getlocale(locale.LC_ALL) # get current locale >>> locale.setlocale(locale.LC_ALL, 'de_DE') # use German locale; name might vary with platform >>> locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut >>> locale.setlocale(locale.LC_ALL, '') # use user's preferred locale >>> locale.setlocale(locale.LC_ALL, 'C') # use default (C) locale >>> locale.setlocale(locale.LC_ALL, loc) # restore saved locale · Subsections · 6.27.1 Background, details, hints, tips and caveats · 6.27.2 For extension writers and programs that embed Python · 6.27.3 Access to message catalogs · Previous: 6.26.1 Example Up: 6.
🌐
Basicexamples
basicexamples.com › example › python › locale-setlocale
Basic example of Python function locale.setlocale()
In the following example, we will use locale.setlocale() to set the locale to the desired language and region in order to format and display currency values correctly.