Pandas: cannot import name compat

15,830

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

Share:
15,830
Vedang Waradpande
Author by

Vedang Waradpande

Updated on June 04, 2022

Comments

  • Vedang Waradpande
    Vedang Waradpande almost 2 years

    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.

  • m33n
    m33n over 5 years
    Can you uninstall pandas and reinstall it again? I know it sounds classic but I remembered that worked for me
  • Pierre Delecto
    Pierre Delecto over 5 years
    I am experiencing the same issue. I have tried updating nltk as well as uninstalling and reinstalling pandas with no success.
  • Pierre Delecto
    Pierre Delecto over 5 years
    After reopening my IDE (Spyder) the problem was solved.
  • aunsid
    aunsid over 4 years
    I has the same issue and I solved it by reinstalling pandas. Since the OP has mentioned that he is using conda. for Uninstallation conda remove --force pandas. Installing it back again conda install -c anaconda pandas