pandas 熊猫:无法导入名称兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52833698/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 06:05:15  来源:igfitidea点击:

Pandas: cannot import name compat

pythonpandasanaconda

提问by Vedang Waradpande

I have some code, preprocess_align.pywhich runs perfectly on my PC but I get an ImportErrorwhen running it on a server. The ImportErrorsupposedly comes when pandasis imported. Here is the error:

我有一些代码,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

The Python version is Python 2.7.14 |Anaconda custom (64-bit)and I have already used conda update pandasto update the version to the latest.

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

Any help is appreciated.

任何帮助表示赞赏。

回答by Z-Y00

You didn't tell us your pandas version, for 0.25,0.24,0.23 as the doc says about pandas.compat

您没有告诉我们您的 Pandas 版本,如文档所说的关于 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. 

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

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

it seems that downgrade to 0.23 works for me. you may use

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

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

and in 0.24 https://pandas.pydata.org/pandas-docs/version/0.24/reference/index.html

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

and in stable(Now 0.25) https://pandas.pydata.org/pandas-docs/stable/reference/index.html?highlight=compat

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

回答by m33n

Try installing this first:

先尝试安装这个:

conda install nltk

And then check again

然后再次检查