Pandas: Unable to import name compatible
I
have some code, preprocess_align.py
, it works perfectly on my PC, but I get ImportError
when running on the server. ImportError
should appear 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),
I’ve used conda update pandas
to update the version to the latest.
Thanks for any help.
Solution
You didn’t tell us your version of pandas, as stated in the documentation about 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.
Such as 0.23
https://pandas.pydata.org/pandas-docs/version/0.23/api.html?highlight=compat
Downgrading to 0.23 seems to work for me.
You can use
it
pip uninstall pandas
pip install --upgrade pandas==0.23.0
At 0.24
https://pandas.pydata.org/pandas-docs/version/0.24/reference/index.html
and in steady state (now 0.25)
https://pandas.pydata.org/pandas-docs/stable/reference/index.html?highlight=compat