When you running Python script on Mac OS, you may occurs Python error like this one:

Traceback (most recent call last):
  File "/usr/local/bin/b2", line 11, in <module>
    load_entry_point('b2==1.4.3', 'console_scripts', 'b2')()
  File "build/bdist.macosx-10.15-x86_64/egg/b2/console_tool.py", line 1625, in main
  File "build/bdist.macosx-10.15-x86_64/egg/b2/console_tool.py", line 1480, in run_command
  File "build/bdist.macosx-10.15-x86_64/egg/b2/console_tool.py", line 1580, in _setup_logging
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 545, in getdefaultlocale
    return _parse_localename(localename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 477, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

Solution

Edit ~/.bash_profile if you are using bash or ~/.zshrc for zsh and add these lines.

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

In some case, you may need to set LC_CTYPE.

export LC_CTYPE=en_US.UTF-8

Restart your terminal or computer or run this command to reload environment variables.

# bash
source ~/.bash_profile

# zsh
source ~/.zshrc

To make sure it was set, check with echo command.

echo $LC_ALL
echo $LANG
echo $LC_CTYPE