Skip to content
Advertisement

Python setlocale with empty string (default locale) gives “unsupported locale setting”

I’m getting the following error:

JavaScript

The setup is a newly installed and updated Fedora 34 system with Python 3.9.6. The error occurs when running Lutris, and also when typing the commands into IDLE. Here is the exact backtrace from Lutris:

JavaScript

Given that, according to the Python docs, “An empty string specifies the user’s default settings,” I figured maybe my default locale (en_AU.UTF-8) wasn’t supported at some level of the stack. But the following all work fine:

JavaScript

And oddly, the error doesn’t happen when I run python in a terminal and type the commands there!

JavaScript

So I have no idea what locale Python thinks it’s setting when I run IDLE or Lutris from the desktop, but it’s evidently not the same one set when I use the terminal. How can I debug this error?

(Incidentally, running Lutris from the command line has been a successful workaround.)

Advertisement

Answer

The problem is the environment variable LC_TIME. Apparently I have it set to en_150.UTF-8 from the desktop, but to C.UTF-8 from the terminal.

Cimbali’s comment set me on the right track. I looked at the environment variables using os.environ, within both IDLE-started-from-the-desktop and Python-started-from-the-terminal.

The ones that appeared locale-related were LANG, LANGUAGE, and LC_TIME. The first two were the same between the two cases, but the last one differed.

And this made the error go away:

JavaScript

Which just leaves me wondering, what the heck is en_150? Is it because I have my desktop set to 24-hour time rather than the default? (Also wondering whether a bug report/request for more descriptive error messages would be useful for Python.)

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement