3

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.

Vedang Waradpande
  • 660
  • 1
  • 6
  • 8

1 Answers1

3

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

Y00
  • 666
  • 1
  • 7
  • 23
  • 2
    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 – aunsid Sep 16 '19 at 17:42