熊猫:无法导入名称兼容

时间:2018-10-16 10:47:16

标签: python pandas anaconda

我有一些代码preprocess_align.py可以在我的PC上完美运行,但是在服务器上运行时却得到ImportError。据推测,ImportError是在导入pandas时出现的。这是错误:

Traceback (most recent call last):
  File "get_features.py", line 12, in <module>
    import preprocess_align as prep
  File "/home/influenza/preprocess_align.py", line 7, in <module>
    import pandas as pd
  File "/home/influenza/anaconda2/lib/python2.7/site-packages/pandas/__init__.py", line 42, in <module>
    from pandas.core.api import *
  File "/home/influenza/anaconda2/lib/python2.7/site-packages/pandas/core/api.py", line 10, in <module>
    from pandas.core.groupby.groupby import Grouper
  File "/home/influenza/anaconda2/lib/python2.7/site-packages/pandas/core/groupby/__init__.py", line 2, in <module>
    from pandas.core.groupby.groupby import (
  File "/home/influenza/anaconda2/lib/python2.7/site-packages/pandas/core/groupby/groupby.py", line 16, in <module>
    from pandas import compat
ImportError: cannot import name compat

Python版本为Python 2.7.14 |Anaconda custom (64-bit),我已经使用conda update pandas将版本更新为最新版本。

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

尝试先安装此软件:

conda install nltk

然后再次检查

答案 1 :(得分:0)

您没有告诉我们您的熊猫版本,正如文档中关于pandas.compat所说的那样,为0.25,0.24,0.23

Warning

The pandas.core, pandas.compat, and pandas.util top-level modules are PRIVATE. Stable functionality in such modules is not guaranteed. 

如0.23 https://pandas.pydata.org/pandas-docs/version/0.23/api.html?highlight=compat

似乎降级到0.23对我有用。 您可以使用

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

并在0.24中 https://pandas.pydata.org/pandas-docs/version/0.24/reference/index.html

且稳定(现在为0.25) https://pandas.pydata.org/pandas-docs/stable/reference/index.html?highlight=compat