Help:Locale errors

From Wikitech

Locale errors are some errors regarding the language of a system. This typically occurs to new instances in the Wikimedia Labs cluster (running Ubuntu 12.04/precise). This page would walk you through solving that issue.

How it happens

Using the pywikipediabot's interwiki.py script as an example here.

Immediately after creating the new instance that you would like to use, you may see errors like:

Python
Traceback (most recent call last):
  File "interwiki.py", line 375, in <module>
    import wikipedia as pywikibot
  File "/home/hydriz/pywikipedia/wikipedia.py", line 147, in <module>
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python2.7/locale.py", line 539, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
Perl
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_TIME = "en_SG.UTF-8",
	LC_MONETARY = "en_SG.UTF-8",
	LC_ADDRESS = "en_SG.UTF-8",
	LC_TELEPHONE = "en_SG.UTF-8",
	LC_NAME = "en_SG.UTF-8",
	LC_MEASUREMENT = "en_SG.UTF-8",
	LC_IDENTIFICATION = "en_SG.UTF-8",
	LC_NUMERIC = "en_SG.UTF-8",
	LC_PAPER = "en_SG.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory

Such errors can break the interwiki bot script, making the script totally useless on that instance. Below is the way to solve this troublesome issue.

Solution

Run the following command to install the required language packs:

sudo apt-get install language-pack-en-base

And to also rebuild it again to ensure it works:

sudo dpkg-reconfigure locales

...and you are done!