我刚刚将iPython升级到Jupyter并希望再次检查我的一个图表以确认一切正常。它不是......
在我有这个命令的第一行
%pylab
结果是一长串错误消息,如下所示:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-4ab7ec3413a5> in <module>()
----> 1 get_ipython().magic('pylab')
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site- packages/IPython/core/interactiveshell.py in magic(self, arg_s)
2334 magic_name, _, magic_arg_s = arg_s.partition(' ')
2335 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2336 return self.run_line_magic(magic_name, magic_arg_s)
2337
2338 #-------------------------------------------------------------------------
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
2255 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2256 with self.builtin_trap:
-> 2257 result = fn(*args,**kwargs)
2258 return result
2259
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/magics/pylab.py in pylab(self, line)
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
191 # but it's overkill for just that one bit of state.
192 def magic_deco(arg):
--> 193 call = lambda f, *a, **k: f(*a, **k)
194
195 if callable(arg):
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/magics/pylab.py in pylab(self, line)
154 import_all = not args.no_import_all
155
--> 156 gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
157 self._show_matplotlib_backend(args.gui, backend)
158 print ("Populating the interactive namespace from numpy and matplotlib")
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/interactiveshell.py in enable_pylab(self, gui, import_all, welcome_message)
3169 from IPython.core.pylabtools import import_pylab
3170
-> 3171 gui, backend = self.enable_matplotlib(gui)
3172
3173 # We want to prevent the loading of pylab to pollute the user's
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
3118 """
3119 from IPython.core import pylabtools as pt
-> 3120 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
3121
3122 if gui != 'inline':
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/pylabtools.py in find_gui_and_backend(gui, gui_select)
237 """
238
--> 239 import matplotlib
240
241 if gui and gui != 'auto':
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/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']:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/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
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/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:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/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:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/contextlib.py in __enter__(self)
57 def __enter__(self):
58 try:
---> 59 return next(self.gen)
60 except StopIteration:
61 raise RuntimeError("generator didn't yield") from None
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/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"
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/locale.py in getdefaultlocale(envvars)
554 else:
555 localename = 'C'
--> 556 return _parse_localename(localename)
557
558
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/locale.py in _parse_localename(localename)
482 elif code == 'C':
483 return None, None
--> 484 raise ValueError('unknown locale: %s' % localename)
485
486 def _build_localename(localetuple):
ValueError: unknown locale: UTF-8
我在Mac OSX 10.11.1上运行它,而我的Python是3.4.1版本。
真的很奇怪 - 在升级到Jupyter之前,一切都运转良好?
答案 0 :(得分:0)
我找到了解决方案here。
将以下行添加到.bash_profile
,然后添加$source .bash_profile
以激活它:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
这至少对我有用。