Mac OS X – ValueError: unknown locale: UTF-8

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/", line 568, in getdefaultlocale
return _parse_localename(localename)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/", line 495, in _parse_localename
raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: UTF-8

To Solve the above issue you will need to add the below variables in your .profile or .bash_profile

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

From the Launchpad, open the Terminal

Type nano .profile
Nano is an easy to use editor

Copy the below lines of code
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Press Ctrl+O to save the lines
Press Return to Save
Press Ctrl+X to Exit

To verify that the variables have been added to the .profile, use the below code in the terminal

open -e .profile

Try running your program once again. If the issue has not been resolved, use the same approach with the file .bash_profile