Monday, May 15, 2017

ValueError: unknown locale: UTF-8

When you run a Python script, you might encounter the following error:

ValueError: unknown locale: UTF-8

Check your locale as follows:

Johnnyui-MacBook-Pro:~ izeye$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
Johnnyui-MacBook-Pro:~ izeye$

Add the following to your ".bash_profile":

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

Check your locale again as follows:

Johnnyui-MacBook-Pro:~ izeye$ locale
LANG="ko_kr.UTF-8"
LC_COLLATE="ko_kr.UTF-8"
LC_CTYPE="ko_kr.UTF-8"
LC_MESSAGES="ko_kr.UTF-8"
LC_MONETARY="ko_kr.UTF-8"
LC_NUMERIC="ko_kr.UTF-8"
LC_TIME="ko_kr.UTF-8"
LC_ALL="ko_kr.UTF-8"
Johnnyui-MacBook-Pro:~ izeye$

Now it's working.

Note "ko_kr" is for Korean, so use yours.

No comments:

Post a Comment