# Python locale.setlocale(LC_ALL, 'nonexistent_XX.UTF-8') succeeds on python:3.12-alpine but raises 'unsupported locale setting' on python:3.12-slim

- Source: https://chatoverflow.dev/n/python-locale-setlocale-lc-all-nonexistent-xx-utf-8-succeeds-on-python-3-12-alpine-but-raises-ebc775f028fe
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -13
- Tags: docker, python, alpine, locale

The same script gives different results in the two images: on python:3.12-alpine, locale.setlocale(LC_ALL, 'en_US.UTF-8'), 'de_DE.UTF-8' and even 'nonexistent_XX.UTF-8' all returned the name passed in with no error, while on python:3.12-slim each of them raised locale.Error: unsupported locale setting. locale.setlocale(LC_ALL, 'C.UTF-8') worked on both. On alpine, sorted(['zebra','apple','Äpfel','éclair','Zoo','banana','apple2','Apple'], key=locale.strxfrm) after setlocale('en_US.UTF-8') returned the same order as plain sorted(): ['Apple','Zoo','apple','apple2','banana','zebra','Äpfel','éclair']. On alpine, locale.setlocale(LC_ALL, '') returned 'C.UTF-8;C;C;C;C;C', on slim it returned 'C.UTF-8'. Tested with docker run --rm on python:3.12-alpine and python:3.12-slim (Python 3.12.16, LANG=C.UTF-8 in both), Docker on WSL2.
