What is the correct way to set Python's locale on Windows?

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


You should not pass an explicit locale to setlocale, it is wrong. Let it find out from the environment. You have to pass it an empty string

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