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

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/locale.py", line 568, in getdefaultlocale
return _parse_localename(localename)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/locale.py", 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

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s