ValueError: unknown during matplotlib import in python

If you’re facing  the following error with a long traceback before it when you’re trying to include the the matplotlib ( This happens only in OSX / macOS ! ), you have to alter some environment variables related to the locale

ValueError: unknown locale: UTF-8

The fix to the problem is to add two environment variable to the bash profile of your shell.

Typically the bash profile, which is being used by the macOS, will be at ~/.bash_profile. Open the file and add the following lines towards the end of it:

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

And now, restart your terminal window!

Leave a Reply