Message192422
On Mac OS X 10.8 with the default language set to English (System Preferences | Language and Text), the default terminal application sets the LC_CTYPE environment variable to "UTF-8". If you run Python from the terminal and try to use locale.getdefaultlocate(), you get the following error:
> python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] 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 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 496, in getdefaultlocale
return _parse_localename(localename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
(The stacktrace is from Python 2.7 but Python 3.3 suffers from the same problem.)
There are numerous workarounds for this problem (turning off the "Set locale environment variables on startup" option in the terminal settings, or adding "export LC_CTYPE=en_US.UTF8" to .bash_profile, selecting a language other than English in the Language & Text settings), but these require additional configuration from the user's side.
I think that the more useful behavior is for Python to handle this behavior of the system and not crash, even though it doesn't strictly comply to the POSIX standard.
The attached patch (against current Python 3.4 master branch) is one possible fix. |
|
Date |
User |
Action |
Args |
2013-07-06 12:19:03 | Dmitry.Jemerov | set | recipients:
+ Dmitry.Jemerov |
2013-07-06 12:19:03 | Dmitry.Jemerov | set | messageid: <1373113143.69.0.513997485887.issue18378@psf.upfronthosting.co.za> |
2013-07-06 12:19:03 | Dmitry.Jemerov | link | issue18378 messages |
2013-07-06 12:19:03 | Dmitry.Jemerov | create | |
|