解决python2 ImportError: cannot import name compat

导入pandas包时出现ImportError: cannot import name compat 问题

我是用的python2.7.13,在导入pandas包时出现了下面错误。

>>> import pandas
Traceback (most recent call last):
  File "", line 1, in <module>
  File "/home/###/miniconda3/lib/python2.7/site-packages/pandas/__init__.py", line 42, in <module>
    from pandas.core.api import *
  File "/home/###/miniconda3/lib/python2.7/site-packages/pandas/core/api.py", line 10, in <module>
    from pandas.core.groupby import Grouper
  File "/home/###/miniconda3/lib/python2.7/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
    from pandas.core.groupby.groupby import GroupBy  # noqa: F401
  File "/home/###/miniconda3/lib/python2.7/site-packages/pandas/core/groupby/groupby.py", line 20, in <module>
    from pandas import compat
ImportError: cannot import name compat

网上有很多解决办法比如grouby.py中改变导入compat的方法;重装matplotlib等等,都不成功。

最终的解决办法是是将pandas降级
原来的pandas版本:

 print ("pandas version:{}".format(pandas.__version__))
 pandas version:0.24.0

现在卸载pandas重装0.23版本:

 pip uninstall pandas
 pip install --upgrade pandas==0.23.0

现在的版本:

print ("pandas version:{}".format(pandas.__version__))
pandas version:0.24.0

导入pandas试一试:

>>> import pandas
>>>

成功!!

你可能感兴趣的:(python,linux)