Fix “ValueError: unknown locale: UTF-8″ under Mac OS X 10.8 Mountain Lion

Today I was trying the Writing your first Django app tutorial, and when I run the syncdb command I got this error:

ValueError: unknown locale: UTF-8

The solution was really simple I just needed to export some variables in my bash enviroment. So I edited my .bash_profile file adding these lines:

export LANG="es_ES.UTF-8"
export LC_COLLATE="es_ES.UTF-8"
export LC_CTYPE="es_ES.UTF-8"
export LC_MESSAGES="es_ES.UTF-8"
export LC_MONETARY="es_ES.UTF-8"
export LC_NUMERIC="es_ES.UTF-8"
export LC_TIME="es_ES.UTF-8"
export LC_ALL=

where es_ES.UTF-8 should be your locale string. To test if it worked for you just reload the console and run this code:

python -c 'import locale; print(locale.getdefaultlocale());'

You should get something like this:

('es_ES', 'UTF8')