【问题标题】:pandas-compat: 'import pandas' gives AttributeError: module 'pandas' has no attribute 'compat'pandas-compat:'import pandas' 给出 AttributeError:模块 'pandas' 没有属性 'compat'
【发布时间】:2018-02-03 01:04:50
【问题描述】:
>>> 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'

我知道还有很多其他类似的问题,但没有一个有帮助。我试过重新安装熊猫:

sudo pip3 uninstall pandas
sudo pip3 install pandas

我还确保已将以下内容添加到我的 bash 个人资料中:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

【问题讨论】:

  • 你试过了吗pip install pandas-compat
  • 在阅读您的评论之前,我最终重新启动了我的机器并且我收到了一个新错误:AttributeError: module 'pandas' has no attribute 'tseries'。我试过 sudo pip3 install pandas-tseries 它说 pip 找不到匹配的分布
  • pandas 的哪个版本发生了这种情况?我从来没有遇到过你的问题。 pandas-compat 也是 pandas 中的一个子包,也是独立的。

标签: python pandas installation compatibility


【解决方案1】:

我相信您说的是Pandas API 兼容层 导入。

通过PIP获取最新的稳定版本:

$ pip install pandas-compat

或者,获取最新的开发版本:

$ pip install git+https://github.com/pandas-compat/pandas-compat.git

你可以这样使用:

import pandas_compat as pdc
pdc.is_datetime64tz_dtype(...)
pdc.infer_dtype(...)

【讨论】:

  • pandas-compat 也是pandas 中的一个子包,并且是独立的(而不是pandas 的先决条件)。令人困惑。
【解决方案2】:

问题出在pandas包api变化

Warning

The pandas.core, pandas.compat, and pandas.util top-level modules are PRIVATE. Stable functionality in such modules is not guaranteed. 

如 0.23 https://pandas.pydata.org/pandas-docs/version/0.23/api.html?highlight=compat

在 0.24 中 https://pandas.pydata.org/pandas-docs/version/0.24/reference/index.html

并且稳定(现在 0.25) https://pandas.pydata.org/pandas-docs/stable/reference/index.html?highlight=compat

你可以使用

 pip uninstall pandas
 pip install --upgrade pandas==0.23.0

要解决这个问题,它对我有用

【讨论】:

    【解决方案3】:

    如果您使用的是 Anaconda
    只需使用

    conda install pandas

    这对我有用

    【讨论】:

      【解决方案4】:

      你可以试试

      conda install pandas-compat
      

      但是如果你得到错误

      “PackagesNotFoundError:当前频道无法提供以下软件包:...”

      使用

      conda install pandas-compat --channel conda-forge
      

      source

      【讨论】:

        【解决方案5】:

        在尝试了以上所有建议之后。以下对我有用:

        conda install -f pandas
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-11-09
          • 1970-01-01
          • 2016-11-28
          • 2019-05-23
          • 2018-09-18
          • 1970-01-01
          • 1970-01-01
          • 2017-09-27
          相关资源
          最近更新 更多