IPython Notebook语言环境错误 [英] IPython Notebook locale error

查看:226
本文介绍了IPython Notebook语言环境错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装最新的 Mac OSX 64位Anaconda Python发行版后,我在尝试时遇到了ValueError启动IPython笔记本。

After installing the latest Mac OSX 64-bit Anaconda Python distribution, I keep getting a ValueError when trying to start the IPython Notebook.

启动ipython工作正常:

Starting ipython works fine:

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笔记本:

But starting ipython notebook:

4-millerc-~:ipython notebook

导致ValueError(跟踪):

Results in the ValueError (with traceback):

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

运行<来自终端的code> 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=


推荐答案

我在这里总结一下可以找到的解决方案: http://blog.lobraun.de/2009/04/11/mercurial-on-mac-os-x-valueerror-unknown-locale-ut f-8 /

I summarize here the solution to be found on: http://blog.lobraun.de/2009/04/11/mercurial-on-mac-os-x-valueerror-unknown-locale-utf-8/

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

I added these lines to my .bash_profile:

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

我重新加载了个人资料:

I reloaded the profile:

source ~/.bash_profile

然后我再次运行 ipython

ipython notebook



更改区域设置



以上内容适用于美国语言环境中的英语语言。人们可能需要不同的设置。

Changing locales

The above will work for the English language in a US locale. One may want different settings.

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

At the risk of stating the obvious, to discover the current settings for your system, use:

$ locale

并检索清单系统上所有有效设置:

And to retrieve a list of all valid settings on your system:

$ locale -a

然后选择您喜欢的语言环境。例如,对于瑞士法语区域设置,解决方案如下所示:

Then choose your preferred locale. For example, for a Swiss French locale, the solution would look like this:

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

这篇关于IPython Notebook语言环境错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆