编程语言
首页 > 编程语言> > Python – ValueError:未知语言环境:UTF-8

Python – ValueError:未知语言环境:UTF-8

作者:互联网

参见英文答案 > Pelican 3.3 pelican-quickstart error “ValueError: unknown locale: UTF-8”                                    5个
我运行包含Pandas的python脚本(导致问题的一个)库我得到了这个错误:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import pandas
ImportError: No module named pandas

但是,如果我从包路径导入以确保它检测到Pandas库,我收到此错误消息

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import pandas
  File "/usr/local/lib/python2.7/site-packages/pandas/__init__.py", line 44, in <module>
    from pandas.core.api import *
  File "/usr/local/lib/python2.7/site-packages/pandas/core/api.py", line 9, in <module>
    from pandas.core.groupby import Grouper
  File "/usr/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 16, in <module>
    from pandas.core.frame import DataFrame
  File "/usr/local/lib/python2.7/site-packages/pandas/core/frame.py", line 41, in <module>
    from pandas.core.series import Series
  File "/usr/local/lib/python2.7/site-packages/pandas/core/series.py", line 2864, in <module>
    import pandas.tools.plotting as _gfx
  File "/usr/local/lib/python2.7/site-packages/pandas/tools/plotting.py", line 28, in <module>
    import pandas.tseries.converter as conv
  File "/usr/local/lib/python2.7/site-packages/pandas/tseries/converter.py", line 7, in <module>
    import matplotlib.units as units
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1131, in <module>
    rcParams = rc_params()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 975, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1100, in rc_params_from_file
    config_from_file = _rc_params_in_file(fname, fail_on_error)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
    with _open_file_or_url(fname) as fd:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
    encoding = locale.getdefaultlocale()[1]
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 543, in getdefaultlocale
    return _parse_localename(localename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

我已经使用这些行更新了我的.bash_profile和.bashrc,但即使我已经重启终端和我的机器仍然无法工作.

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="it_IT.UTF-8"

我还启用了在终端首选项中启动时设置语言环境变量.

enter image description here

我担心因为El Capitan引起的问题.

解决方法:

编辑:Pandas及其依赖项在非C语言环境中发现了localization bugs,并在最近的版本中得到修复.

当我通过设置为it_IT.UTF-8的终端中的sudo pip安装pandas将最新版本的Pandas下载到OS X Yosemite计算机上,然后将其导入新的Python会话时,我无法重现此问题.

我现在最好的猜测 – 我强调这只是一个猜测 – 该文件夹中的Pandas版本早于那些修复,并在it_IT.UTF-8中被破坏. (我确实认为这比El Capitan特有的问题更有可能.)

您的LC_ALL =未设置.这似乎不寻常;基于other answers here我认为您应该尝试将其设置为LC_ALL =“it_IT.UTF-8”并删除其他LC_设置.

然后保存.bash_profile,打开一个新的终端选项卡,然后重试.

标签:python,bash,pandas,osx-elcapitan
来源: https://codeday.me/bug/20190623/1271510.html