Error setting locale in python

Bryan Blackburn blb at macports.org
Thu Jul 22 12:34:00 PDT 2010


On Thu, Jul 22, 2010 at 08:32:06PM +0200, Harald Hanche-Olsen said:
> python2.5 and python2.6 both don't like my locale setting:
> 
>   ; python2.6
>   Python 2.6.5 (r265:79063, Jul 16 2010, 21:35:10) 
>   [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>   Type "help", "copyright", "credits" or "license" for more information.
>   >>> import locale
>   >>> locale.setlocale(locale.LC_ALL,'')
>   Traceback (most recent call last):
>     File "<stdin>", line 1, in <module>
>     File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/locale.py", line 513, in setlocale
>       return _setlocale(category, locale)
>   locale.Error: unsupported locale setting
> 
> /usr/bin/python, on the other hand, has no such problems.
> My locale setting may be a bit unusual, but not illegal AFAIK:
> 
>   ; locale
>   LANG=
>   LC_COLLATE="C"
>   LC_CTYPE="en_US.UTF-8"
>   LC_MESSAGES="C"
>   LC_MONETARY="C"
>   LC_NUMERIC="C"
>   LC_TIME="C"
>   LC_ALL=
> 
> Any suggestions? Is this a bug, or am I actually not allowed to
> specify my locale that way?

Do you have anything else in your env that could be affecting the locale
stuff?  If I use those LANG/LC settings you've listed, the MacPorts python
seems okay with it:

% env LANG= LC_COLLATE="C" LC_CTYPE="en_US.UTF-8" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL= /mp/bin/python2.6
Python 2.6.5 (r265:79063, Jul 17 2010, 19:33:53) 
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL,'')
'C/en_US.UTF-8/C/C/C/C'

Though this is on 10.6, whereas I'm guessing you're on an earlier version
since the gcc listed for your build is 4.0.1.

Bryan


> 
> - Harald


More information about the macports-users mailing list