我运行包含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"
我还在终端首选项中启用了Set locale environment variables on startup
。
我担心因为El Capitan引起的问题。
答案 0 :(得分:4)
编辑:Pandas及其依赖项已在非C语言环境中发现并在最近版本中修复了localization bugs。
当我通过设置为it_IT.UTF-8的终端中的sudo pip install 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,打开一个新的终端选项卡,然后重试。