我已经阅读了十几条谷歌条目以及其他有关同一问题的SO问题,但我无法修复它。示例错误代码是:import matplotlib as plt
,但是还有很多其他东西会触发它。
整个输出是:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-11-20da4deed62d> in <module>()
1 #import pandas as pd
----> 2 import matplotlib as plt
/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py in <module>()
1129
1130 # this is the instance used by the matplotlib classes
-> 1131 rcParams = rc_params()
1132
1133 if rcParams['examples.directory']:
/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py in rc_params(fail_on_error)
973 return ret
974
--> 975 return rc_params_from_file(fname, fail_on_error)
976
977
/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py in rc_params_from_file(fname, fail_on_error, use_default_template)
1098 parameters specified in the file. (Useful for updating dicts.)
1099 """
-> 1100 config_from_file = _rc_params_in_file(fname, fail_on_error)
1101
1102 if not use_default_template:
/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py in _rc_params_in_file(fname, fail_on_error)
1016 cnt = 0
1017 rc_temp = {}
-> 1018 with _open_file_or_url(fname) as fd:
1019 try:
1020 for line in fd:
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.pyc in __enter__(self)
15 def __enter__(self):
16 try:
---> 17 return self.gen.next()
18 except StopIteration:
19 raise RuntimeError("generator didn't yield")
/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py in _open_file_or_url(fname)
998 else:
999 fname = os.path.expanduser(fname)
-> 1000 encoding = locale.getdefaultlocale()[1]
1001 if encoding is None:
1002 encoding = "utf-8"
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.pyc in getdefaultlocale(envvars)
541 else:
542 localename = 'C'
--> 543 return _parse_localename(localename)
544
545
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.pyc in _parse_localename(localename)
473 elif code == 'C':
474 return None, None
--> 475 raise ValueError, 'unknown locale: %s' % localename
476
477 def _build_localename(localetuple):
ValueError: unknown locale: UTF-8
此错误出现在Jupyter笔记本中,尝试使用不同的代码,但到目前为止还没有在终端中。
我认为他们可能会使用不同的二进制文件,但它看起来并不像print sys.executable
那样:
/usr/local/opt/python/bin/python2.7
/usr/local/opt/python/bin/python2.7
试图了解更多信息,我在Python CLI中运行:
>>> import locale
>>> print locale.getdefaultlocale()
('en_US', 'UTF-8')
然后在笔记本中:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-35604c361744> in <module>()
1 import locale
----> 2 print locale.getdefaultlocale()
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.pyc in getdefaultlocale(envvars)
541 else:
542 localename = 'C'
--> 543 return _parse_localename(localename)
544
545
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.pyc in _parse_localename(localename)
473 elif code == 'C':
474 return None, None
--> 475 raise ValueError, 'unknown locale: %s' % localename
476
477 def _build_localename(localetuple):
ValueError: unknown locale: UTF-8
另一方面, print locale.getlocale()
在两个地方获得相同的输出:(None, None)
我发现的只是我必须修改我的语言环境设置,但它们在终端中看起来很好:
$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
使用两个Jupyter或Ipython实例可以完成所有工作。
所以,我是首先运行jupyter notebook
还是ipython notebook
,然后我去打开一个新的终端标签页并启动第二个 { {1}}或jupyter notebook
,浏览器中的第二个实例(如果我没有添加ipython notebook
部分,则在终端中,我已尝试过所有组合)将运行no区域问题无论如何。
以科学的名义,我关闭了第一个实例,第二个实例的表现同样出色。
我使用运行ZSH的Iterm2。起初我尝试添加这两行:
notebook
如果我评论这些并重新启动控制台,这就是我得到的:
$ head .zshrc
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
在这种情况下,即使Python CLI也会抛出相同的错误。
关于标签1和标签2,我使用$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
和{locale & locale -a } > tab1
对结果进行了比较,但在这方面结果相同:
是的,我已经得到了这些:
{locale & locale -a } > tab2
所以完全失去了这里。如何解决这种疯狂?