python - 将 pylab 与 ipython 一起使用 - ValueError : unknown locale: UTF-8

标签 python matplotlib ipython anaconda

<分区>

我需要安装 ipython 并将 pylab 用于我的信号和系统类。

我已经启动并运行了 ipython(python 版本 3.5)。

我无法让 pylab 初始化。

我已经安装了 matplotlib。 当我在终端中键入 ipython --pylab 时,我得到以下信息:

IPython 4.0.3 -- 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.
[TerminalIPythonApp] WARNING | GUI event loop or pylab initialization failed
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/ruiloureiro/anaconda/lib/python3.5/site-packages/IPython/core/shellapp.py in <lambda>(key)
    217         shell = self.shell
    218         if self.pylab:
--> 219             enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
    220             key = self.pylab
    221         elif self.matplotlib:

/Users/ruiloureiro/anaconda/lib/python3.5/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

/Users/ruiloureiro/anaconda/lib/python3.5/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':

/Users/ruiloureiro/anaconda/lib/python3.5/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':

/Users/ruiloureiro/anaconda/lib/python3.5/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/ruiloureiro/anaconda/lib/python3.5/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/ruiloureiro/anaconda/lib/python3.5/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/ruiloureiro/anaconda/lib/python3.5/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/ruiloureiro/anaconda/lib/python3.5/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

/Users/ruiloureiro/anaconda/lib/python3.5/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/ruiloureiro/anaconda/lib/python3.5/locale.py in getdefaultlocale(envvars)
    557     else:
    558         localename = 'C'
--> 559     return _parse_localename(localename)
    560 
    561 

/Users/ruiloureiro/anaconda/lib/python3.5/locale.py in _parse_localename(localename)
    485     elif code == 'C':
    486         return None, None
--> 487     raise ValueError('unknown locale: %s' % localename)
    488 
    489 def _build_localename(localetuple):

ValueError: unknown locale: UTF-8

知道是什么原因造成的吗?

最佳答案

您可能需要将以下行添加到您的 ~/.bash_profile 中:

$ nano ~/.bash_profile

$ vi ~/.bash_profile

将这些行添加到文件末尾

$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8

将这些行保存到您的个人资料中后,注销并重新登录到 shell,它应该可以工作了。

关于python - 将 pylab 与 ipython 一起使用 - ValueError : unknown locale: UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35923729/

相关文章:

python - 属性名称以下划线结尾是什么意思?

python - 获取 zip 文件中包含的文件的文件列表

python - 为什么我的 JupyterLab 笔记本代码控制台没有按应有的方式显示 'command history'?

python - matplotlib:创建两个(堆叠的)具有共享 X 轴但独立 Y 轴值的子图

python - 使用 iPython 内联图的 SVG 渲染问题

subprocess - 在 IPython 中运行外部命令

python - 在列表解析中使用 if, elif, else, Python

python - 简单的线性搜索测试(python)

python - 带有 2D 数组的 3D 图 python matplotlib

python - 如何将多个数据框绘制到相同的绘图轴