Last Updated: February 25, 2016
·
1.358K
· manas

Set LANG variable in OSX terminal app

Today, I stumbled upon an old issue that affects django and other Python module that use the LANG variable in OSX.

Running createdb command (Django 1.4.3) throws an error:

ValueError: unknown locale: UTF-8

This also affects locale.py. The LANG variable, used to specify the desired locale, is set as UTF-8 in terminal app but it should be of the form:

language[_territory][.codeset]

To see the list of available locales, type:

locale -a

To resolve this uncheck "Set LANG environment variable on sturtup" on the "advanced" tab in Terminal's preferences. [1]

Or you set the variables in .bash_profile [2]:

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

[1] https://code.djangoproject.com/ticket/5846
[2] http://patrick.arminio.info/blog/2012/02/fix-valueerror-unknown-locale-utf8/