问题
>>> import pandas
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import pandas
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas/__init__.py", line 40, in <module>
import pandas.core.config_init
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas/core/config_init.py", line 14, in <module>
import pandas.core.config as cf
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas/core/config.py", line 57, in <module>
import pandas.compat as compat
AttributeError: module 'pandas' has no attribute 'compat'
I know that there are a lot of other similar questions but none have helped. I have tried reinstalling pandas:
sudo pip3 uninstall pandas
sudo pip3 install pandas
I have also ensured that I've added the following to my bash profile:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
回答1:
I believe you are talking about the Pandas API compatiblity layer import.
To get the latest stable release through PIP :
$ pip install pandas-compat
Or, to get the latest development version :
$ pip install git+https://github.com/pandas-compat/pandas-compat.git
You can use this as:
import pandas_compat as pdc
pdc.is_datetime64tz_dtype(...)
pdc.infer_dtype(...)
回答2:
The problem lies in the pandas package api changes
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
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
you may use
pip uninstall pandas
pip install --upgrade pandas==0.23.0
to fix this, it works for me
回答3:
if you are using Anaconda
Simply use
conda install pandas
This works for me
回答4:
After trying all the above suggestions. The following worked for me:
conda install -f pandas
回答5:
You can try
conda install pandas-compat
but if you get the error
"PackagesNotFoundError: The following packages are not available from current channels: ..."
use
conda install pandas-compat --channel conda-forge
source
来源:https://stackoverflow.com/questions/45873624/pandas-compat-import-pandas-gives-attributeerror-module-pandas-has-no-attr