This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 Dmitry.Jemerov
收信人 Dmitry.Jemerov
日期 2013-07-06.12:19:02
SpamBayes Score -1.0
Marked as misclassified
Message-id <1373113143.69.0.513997485887.issue18378@psf.upfronthosting.co.za>
In-reply-to
内容
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.
历史
日期 用户 动作 参数
2013-07-06 12:19:03Dmitry.Jemerov修改recipients: + Dmitry.Jemerov
2013-07-06 12:19:03Dmitry.Jemerov修改messageid: <1373113143.69.0.513997485887.issue18378@psf.upfronthosting.co.za>
2013-07-06 12:19:03Dmitry.Jemerov链接issue18378 messages
2013-07-06 12:19:03Dmitry.Jemerov创建