Pandas: cannot import name compat

时光怂恿深爱的人放手 提交于 2020-01-21 14:42:13

问题


I have some code, preprocess_align.py which runs perfectly on my PC but I get an ImportError when running it on a server. The ImportError supposedly comes when pandas is imported. Here is the error:

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 pandas to update the version to the latest.

Any help is appreciated.


回答1:


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

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

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

 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

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




回答2:


Try installing this first:

conda install nltk

And then check again



来源:https://stackoverflow.com/questions/52833698/pandas-cannot-import-name-compat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!