【发布时间】:2016-01-21 23:18:38
【问题描述】:
我是 python 新手,正在努力在 mac 上使用 ipython。 有人告诉我使用 anaconda、ipython 笔记本寻求帮助。
我在我的 Mac 上安装了 anaconda。 我必须使用 numpy、scipy 和 matplotlib 框架 numpy,scipy 工作正常 但是当我尝试使用它时,matplotlib 会出错。 或 %pylab 抛出错误。
这是完整的跟踪enter link description here
如果链接不起作用,这是错误(完整堆栈跟踪)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-5c1faa999e5b> in <module>()
----> 1 get_ipython().magic(u'pylab')
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc 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 #-------------------------------------------------------------------------
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc 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
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc in pylab(self, line)
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/magic.pyc 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):
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc 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")
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc 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
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc 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':
/Users/abhi/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in find_gui_and_backend(gui, gui_select)
237 """
238
--> 239 import matplotlib
240
241 if gui and gui != 'auto':
/Users/abhi/anaconda2/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']:
/Users/abhi/anaconda2/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
/Users/abhi/anaconda2/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:
/Users/abhi/anaconda2/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:
/Users/abhi/anaconda2/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")
/Users/abhi/anaconda2/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"
/Users/abhi/anaconda2/lib/python2.7/locale.pyc in getdefaultlocale(envvars)
541 else:
542 localename = 'C'
--> 543 return _parse_localename(localename)
544
545
/Users/abhi/anaconda2/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
【问题讨论】:
-
你能发布完整的堆栈跟踪吗?
-
@rtemperv 更新了我的问题,请看底部。这是完整的堆栈跟踪pastie.org/10696434#13
-
链接未加载,你不能直接将文本粘贴到问题中吗?
-
没有问题,为了将来参考,我通过网络搜索“ValueError: unknown locale: UTF-8”找到了答案,这是你堆栈跟踪的最后一行,通常是这一行其中包含错误的重要部分
标签: python macos matplotlib ipython anaconda