IPython Notebook 语言环境错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15526996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IPython Notebook locale error
提问by cmiller8
After installing the latest Mac OSX 64-bit Anaconda Python distribution, I keep getting a ValueError when trying to start the IPython Notebook.
安装最新的Mac OSX 64 位 Anaconda Python 发行版后,我在尝试启动 IPython Notebook 时不断收到 ValueError。
Starting ipython works fine:
启动 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.
But starting ipython notebook:
但是启动 ipython 笔记本:
4-millerc-~:ipython notebook
Results in the ValueError (with traceback):
结果在 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
Running the localecommand from the 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=
采纳答案by daedalus
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/
我在这里总结了可以在以下位置找到的解决方案:http: //blog.lobraun.de/2009/04/11/mercurial-on-mac-os-x-valueerror-unknown-locale-utf-8/
I added these lines to my .bash_profile:
我将这些行添加到我的.bash_profile:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
I reloaded the profile:
我重新加载了配置文件:
source ~/.bash_profile
I then ran ipythonagain:
然后我又跑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
回答by wRAR
As your LC_CTYPEis wrong, you should find out where that wrong value is set and change it to something like en_US.UTF-8.
由于您LC_CTYPE错了,您应该找出错误值的设置位置并将其更改为类似en_US.UTF-8.
回答by asmeurer
This is a bug in the OS X Terminal app that only shows up in certain locales (country/language combinations). Open Terminal in /Applications/Utilities and uncheck the box “Set locale environment variables on startup”.
这是 OS X 终端应用程序中的一个错误,仅在某些区域设置(国家/语言组合)中出现。在 /Applications/Utilities 中打开终端并取消选中“启动时设置区域设置环境变量”框。
This will set your LANGenvironment variable to be empty. This may cause terminal use to incorrect settings for your locale. The locale command in the Terminal will tell you what settings are used. To use the correct language, add a line to your bash profile (typically ~/.profile)
这会将您的LANG环境变量设置为空。这可能会导致终端使用您的区域设置不正确。终端中的 locale 命令会告诉您使用了哪些设置。要使用正确的语言,请在您的 bash 配置文件中添加一行(通常为~/.profile)
export LANG=your-lang
Replace your-langwith the correct locale specifier for your language. The command locale -awill show you all the specifiers. For example, the language code for US English is en_US.UTF-8. The locale affects what translations are used when they are available, and also how dates, currencies, and decimals are formatted.
替换your-lang为您的语言的正确区域设置说明符。该命令locale -a将向您显示所有说明符。例如,美国英语的语言代码是en_US.UTF-8。区域设置会影响可用时使用的翻译,以及日期、货币和小数的格式。
Note, this image and content were taken from http://conda.pydata.org/docs/troubleshooting.html#unknown-locale(I'm also the original author of that page).
请注意,此图片和内容取自http://conda.pydata.org/docs/troubleshooting.html#unknown-locale(我也是该页面的原作者)。
回答by AceRymond
in iTerm going to the menu
在 iTerm 中转到菜单
Preferences -> Profiles -> Terminal -> (Environment)
and then unchecking
然后取消选中
"Set locale variables automatically"
made this error go away.
使这个错误消失了。


