So today I upgraded to bazaar 2.0.2, and I started receiving this message (I’m on snow leopard, btw):
bzr: warning: unknown locale: UTF-8
Could not determine what text encoding to use.
This error usually means your Python interpreter
doesn't support the locale set by $LANG (en_US.UTF-8)
Continuing with ascii encoding.
very strange, since my LANG is actually empty. Similar thing happen when I try to tinker with the locale module
Python 2.5.4 (r254:67916, Nov 30 2009, 14:09:22)
[GCC 4.3.4] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sbo/runtimes/lib/python2.5/locale.py", line 443, in getdefaultlocale
return _parse_localename(localename)
File "/Users/sbo/runtimes/lib/python2.5/locale.py", line 375, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
exporting LANG does not help
sbo@dhcp-045:~ $ export LANG=en_US.UTF-8
sbo@dhcp-045:~ $ bzr
bzr: warning: unknown locale: UTF-8
Could not determine what text encoding to use.
This error usually means your Python interpreter
doesn't support the locale set by $LANG (en_US.UTF-8)
Continuing with ascii encoding.
However, this solved the problem
sbo@dhcp-045:~ $ export LANG=en_US.UTF-8
sbo@dhcp-045:~ $ export LC_ALL=en_US.UTF-8
Python 2.5.4 (r254:67916, Nov 30 2009, 14:09:22)
[GCC 4.3.4] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'UTF8')
Could you please explain what’s going on here, for better googlability ?
2016 UPDATE: Turns out that this is a Python bug since at least 2013, very probably earlier too, consisting in Python not reacting well to non-GNU locales – like those found in Mac OS X and the BSDs. The bug is still open as of September 2016, and affects every Python version.
If there was no
LANGenvironment variable set, chances are you had either anLC_CTYPE(the key variable) orLC_ALL(which overrides if set) environment variable set toUTF-8, which is not a valid OS X locale. It’s easy enough to reproduce with the Apple-supplied/usr/bin/pythonor with a custom python, as in your case, that was built with the 10.6 SDK (probably also the 10.5 SDK). You won’t be able to reproduce it that way with a python.org python; they are currently built with the 10.4 SDK where the locale APIs behave differently.EDIT:
There may be another piece to the puzzle. A quick look at the
bzr2.0.1 I have installed indicates that the message you cite should only show up iflocale.getpreferredencoding()raises alocale.Error. One way that can happen is if the python_locale.soC extension can’t be loaded and that can happen if there are permission problems on it. For example, MacPorts currently is known to have problems setting permissions if you have a customized umask; I’ve been burned by that issue myself. Check the permissions of_locale.soin the pythonlib/python2.5/lib-dynloaddirectory and ensure it is755. The full path for MacPorts should be: