MacOS X: ValueError: unknown locale: UTF-8 (Fixed)

Dec 7, 2016 15:16 · 58 words · 1 minute read python macosx snippet

This typically occurs on MacOS X when executing Python scripts:

  File "/Users/millerc/anaconda/lib/python2.7/", line 503, in getdefaultlocale
    return _parse_localename(localename)
  File "/Users/millerc/anaconda/lib/python2.7/", line 435, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8


Edit ~/.bash_profile (in case of zsh edit ~/.zshenv) as follows:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Reload the profile with command below:

source ~/.bash_profile

We will notify you about new posts every few weeks