pandas Python - ValueError:未知区域设置:UTF-8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33716748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python - ValueError: unknown locale: UTF-8
提问by Mohammad Nurdin
I run the python script that contain Pandas (that one cause the problem) library I got this error:
我运行包含 Pandas(导致问题的那个)库的 python 脚本我收到了这个错误:
Traceback (most recent call last):
File "test.py", line 2, in <module>
import pandas
ImportError: No module named pandas
But if I import from package path to make sure it detects Pandas library, I got this error message
但是,如果我从包路径导入以确保它检测到 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
I already update my .bash_profile
and .bashrc
with these lines but still not working even I already restart the terminal and my machine.
我已经用这些行更新了我的.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"
I'm also enabled Set locale environment variables on startup
in the terminal preferences.
我也在Set locale environment variables on startup
终端首选项中启用。
I'm afraid the problem caused because of El Capitan.
恐怕问题是因为 El Capitan 引起的。
回答by Will Angley
Edit: Pandas, and its dependencies, had localization bugsthat were discovered in non-C locales and fixed in recent versions.
编辑:Pandas 及其依赖项具有在非 C 语言环境中发现并在最新版本中修复的本地化错误。
When I downloaded the latest version of Pandas onto an OS X Yosemite computer via sudo pip install pandas
in a terminal set to it_IT.UTF-8, and then imported it in a new Python session, I wasn't able to reproduce this issue.
当我通过sudo pip install pandas
设置为 it_IT.UTF-8 的终端将最新版本的 Pandas 下载到 OS X Yosemite 计算机上,然后将其导入到新的 Python 会话中时,我无法重现此问题。
My best guess now - and I'd emphasize this is only a guess - is that the version of Pandas in that folder predates those fixes and is broken in it_IT.UTF-8. (I do think this is, on balance, more likely than the issue being specific to El Capitan.)
我现在最好的猜测 - 我要强调这只是一个猜测 - 是该文件夹中的 Pandas 版本早于这些修复并且在 it_IT.UTF-8 中被破坏。(总的来说,我确实认为这比 El Capitan 特有的问题更有可能。)
Your LC_ALL= is unset. That seems unusual; based on other answers hereI think you should try setting it to LC_ALL="it_IT.UTF-8" and remove the other LC_ settings.
您的 LC_ALL= 未设置。这似乎不寻常;基于这里的其他答案,我认为您应该尝试将其设置为 LC_ALL="it_IT.UTF-8" 并删除其他 LC_ 设置。
Then save your .bash_profile, open a new terminal tab, and try again.
然后保存您的 .bash_profile,打开一个新的终端选项卡,然后重试。