在 mac 上使用 ipython(matplotlib),抛出错误

using ipython(matplotlib) on mac, throws error

我是 python 的新手,很难在 mac 上使用 ipython。 有人告诉我使用 anaconda,ipython notebook 寻求帮助。

我在 mac 上安装了 anaoconda。 我必须使用 numpy、scipy 和 matplotlib 框架 numpy,scipy 工作正常 但是当我尝试使用它时,matplotlib 会出错。 或者 %pylab 抛出错误。

我不明白这是什么问题? 这是相同的屏幕截图。

这是完整的轨迹 enter link description here

如果 Link 不起作用

,这是错误(完整堆栈跟踪)
---------------------------------------------------------------------------
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

经过长长的淡褐色 我找到了答案,因为有人在问题下方发表了有用的评论

只需使用以下变量编辑您的 .bash_profile 文件

export LANG="it_IT.UTF-8"  
export LC_COLLATE="it_IT.UTF-8"  
export LC_CTYPE="it_IT.UTF-8"  
export LC_MESSAGES="it_IT.UTF-8"  
export LC_MONETARY="it_IT.UTF-8"  
export LC_NUMERIC="it_IT.UTF-8"  
export LC_TIME="it_IT.UTF-8"  
export LC_ALL=  

它对我有用。 一些有用的链接 1 enter link description here 2 enter link description here