Saturday, April 11, 2009

Mercurial on Mac OS X: ValueError: unknown locale: UTF-8

Mercurial from macports on Mac OX X Leopard gives this error message on any hg command:


Traceback (most recent call last):
File "/opt/local/bin/hg", line 25, in
mercurial.util.set_binary(fp)
File "/opt/local/lib/python2.5/site-packages/mercurial/demandimport.py", line 75, in __getattribute__
self._load()
File "/opt/local/lib/python2.5/site-packages/mercurial/demandimport.py", line 47, in _load
mod = _origimport(head, globals, locals)
File "/opt/local/lib/python2.5/site-packages/mercurial/util.py", line 93, in
_encoding = locale.getlocale()[1]
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/locale.py", line 462, in getlocale
return _parse_localename(localename)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/locale.py", line 375, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

The mercurial-user list has a posting from October 2007 that blames the Mac OS X terminal application.

This really seems to be a problem with the terminal application, because if you start X11 and xterm, hg will start without the error message. In order to work with mercurial on Terminal you need to set LC_ALL and LANG in your .bashrc or .profile, like

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

13 comments:

Anonymous said...

Thanks! Your post came up in the top 3 for my Google search and I got my Mercurial working with the Leopard Terminal soon after.

James said...

Thanks a lot. This solution worked for me.

shiretu said...

Excellent! Works for me too!

Markus said...

You saved me!!! Thanks a lot!

Tiago Matos said...

Tks

akella said...

Helped me as well! Thanks for the post! )

Anonymous said...

Thanks a bunch. It was quick fix.

ravikb said...

Thanks,

Edu said...

Just in case someone has the same error message using svnmerge.py (http://www.orcaware.com/svn/wiki/Svnmerge.py), this is how I fixed it:

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

I am not sure if the first two are needed for svnmerge.py, but the error message was the same and after adding those two I added the third one and it worked.

Anonymous said...

I had the same message with sphinx (sphinx-quickstart). Your trick works like a charme! Thanks.

Reshad said...
This comment has been removed by the author.
Reshad said...

Thanks a lot!
It helped me to run keepnote on my computer
Cheers

jalmiburung said...

Thanks. It works like magic. I didn't know that the solution for this kind of error was so simple.