DEV Community

Deepika Banoth
Deepika Banoth

Posted on • Updated on

How to fix: "locale.Error: unsupported locale setting" on pip install

If you see the following error while installing pip:

Traceback (most recent call last):
     File "/usr/bin/pip", line 11, in <module>
       sys.exit(main())
     File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main
       locale.setlocale(locale.LC_ALL, '')
     File "/usr/lib/python2.7/locale.py", line 581, in setlocale
       return _setlocale(category, locale)
   locale.Error: unsupported locale setting

this means the environment variable LC_ALL is missing or invalid somehow.

FIX :

run the following command:

export LC_ALL=C

and retry installing again.

What is LC_ALL?

LC_ALL is the environment variable that overrides the value of the LANG and the values of any other LC_* environment variables.

In a script, if you want to force a specific setting, as you don't know what settings the user has forced, your safest and generally only option is to force LC_ALL.

The C locale is for computers. In the C locale, characters are single bytes, the charset is ASCII, the sorting order is based on the byte values, the language is usually US English.
You generally run a command with LC_ALL=C to avoid the user's settings to interfere with your script. For example, if you want [a-z] to match the 26 ASCII characters from a to z, you have to set LC_ALL=C.

Hope this helps! :)

Top comments (3)

Collapse
 
devanghingu profile image
Devang Hingu

why it need to assign "C" ? can we assign anything else?

Collapse
 
deepika_banoth profile image
Deepika Banoth • Edited

You generally run LC_ALL=C to avoid user's settings to interfere with your script. The C locale is for computers and in the C locale, characters are single bytes, the charset is ASCII, the sorting order is based on byte values, the language is usually US English.
For example, if you want [a-z] to match the 26 ASCII characters from a to z, you have to set LC_ALL=C

Suppose if you set LC_ALL as es_ES which is European Spanish, it forces the application to use default language for output

$ LC_ALL=es_ES man
¿Qué página de manual desea?

when it is set to C it looks like following:

$ LC_ALL=C man
What manual page do you want?

I hope this helps!

Collapse
 
devanghingu profile image
Devang Hingu

well explained.. it overrides all the other localisation settings.