IPython笔记本区域设置错误

安装最新的Mac OSX 64位Anaconda Python发行版之后 ,在尝试启动IPython Notebook时,我不断收到一个ValueError。

开始ipython正常工作:

3-millerc-~:ipython Python 2.7.3 |Anaconda 1.4.0 (x86_64)| (default, Feb 25 2013, 18:45:56) Type "copyright", "credits" or "license" for more information. IPython 0.13.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. 

但是启动ipython笔记本:

 4-millerc-~:ipython notebook 

ValueError中的结果(带回溯):

 Traceback (most recent call last): File "/Users/millerc/anaconda/bin/ipython", line 7, in <module> launch_new_instance() File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 388, in launch_new_instance app.initialize() File "<string>", line 2, in initialize File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error return method(app, *args, **kwargs) File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 313, in initialize super(TerminalIPythonApp, self).initialize(argv) File "<string>", line 2, in initialize File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error return method(app, *args, **kwargs) File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/core/application.py", line 325, in initialize self.parse_command_line(argv) File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 308, in parse_command_line return super(TerminalIPythonApp, self).parse_command_line(argv) File "<string>", line 2, in parse_command_line File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error return method(app, *args, **kwargs) File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 420, in parse_command_line return self.initialize_subcommand(subc, subargv) File "<string>", line 2, in initialize_subcommand File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error return method(app, *args, **kwargs) File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 352, in initialize_subcommand subapp = import_item(subapp) File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/utils/importstring.py", line 40, in import_item module = __import__(package,fromlist=[obj]) File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/html/notebook/notebookapp.py", line 46, in <module> from .handlers import (LoginHandler, LogoutHandler, File "/Users/millerc/anaconda/lib/python2.7/site-packages/IPython/frontend/html/notebook/handlers.py", line 36, in <module> from docutils.core import publish_string File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/core.py", line 20, in <module> from docutils import frontend, io, utils, readers, writers File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/frontend.py", line 41, in <module> import docutils.utils File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/utils/__init__.py", line 20, in <module> from docutils.io import FileOutput File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/io.py", line 18, in <module> from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput File "/Users/millerc/anaconda/lib/python2.7/site-packages/docutils/utils/error_reporting.py", line 47, in <module> locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1] File "/Users/millerc/anaconda/lib/python2.7/locale.py", line 503, in getdefaultlocale return _parse_localename(localename) File "/Users/millerc/anaconda/lib/python2.7/locale.py", line 435, in _parse_localename raise ValueError, 'unknown locale: %s' % localename ValueError: unknown locale: UTF-8 

从terminal运行locale命令:

 5-millerc-~:locale LANG= LC_COLLATE="C" LC_CTYPE="UTF-8" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL= 

我总结这里的解决scheme: http : //blog.lobraun.de/2009/04/11/mercurial-on-mac-os-x-valueerror-unknown-locale-utf-8/

我将这些行添加到我的.bash_profile

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

我重新加载了configuration文件:

 source ~/.bash_profile 

然后我再次运行ipython

 ipython notebook 

更改区域设置

以上内容适用于美国地区的英语。 人们可能需要不同的设置。

冒着明显的风险,要发现系统的当前设置,请使用:

 $ locale 

并检索系统上所有有效设置的列表:

 $ locale -a 

然后select您的首选区域设置。 例如,对于瑞士法语区域,解决scheme将如下所示:

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

这是OS X Terminal应用程序中的一个错误,只显示在某些语言环境(国家/语言组合)中。 在/ Applications / Utilities中打开terminal,取消勾选“启动时设置语言环境variables”。

在这里输入图像描述

这将设置您的LANG环境variables为空。 这可能会导致terminal使用不正确的设置为您的区域设置。 terminal中的locale命令会告诉你使用了什么设置。 要使用正确的语言,请将一行添加到您的bashconfiguration文件(通常为~/.profile

 export LANG=your-lang 

your-langreplace为您的语言的正确语言环境说明符。 命令locale -a将显示所有的说明符。 例如,美国英语的语言代码是en_US.UTF-8 。 语言环境会影响翻译的可用时间,以及date,货币和小数位的格式。

请注意,此图片和内容来自http://conda.pydata.org/docs/troubleshooting.html#unknown-locale (我也是该网页的原始作者)。

在iTerm进入菜单

 Preferences -> Profiles -> Terminal -> (Environment) 

然后取消选中

 "Set locale variables automatically" 

使这个错误消失。

由于你的LC_CTYPE是错误的,你应该找出错误值设置的位置,并将其改为en_US.UTF-8