Python 导入 pandas_datareader 给出 ImportError:无法导入名称 'is_list_like'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50394873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:29:01  来源:igfitidea点击:

import pandas_datareader gives ImportError: cannot import name 'is_list_like'

pythonpandaspandas-datareader

提问by Raj

I am working in a virtual environment. I am able to import and work in pandas without any error but when I am trying to import pandas_datareader

我在虚拟环境中工作。我能够在没有任何错误的情况下导入和使用 Pandas,但是当我尝试import pandas_datareader

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
from matplotlib import style
import pandas_datareader as web

it is giving following error -

它给出了以下错误 -

Traceback (most recent call last):
  File "stock.py", line 6, in <module>
    import pandas_datareader as web
  File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/__init__.py", line 2, in <module>
    from .data import (DataReader, Options, get_components_yahoo,
  File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/data.py", line 14, in <module>
    from pandas_datareader.fred import FredReader
  File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/fred.py", line 1, in <module>
    from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
(env) xxxxx@xxxxx-yyyyy ~/pyt $ python stock.py
Traceback (most recent call last):
  File "stock.py", line 6, in <module>
    import pandas_datareader
  File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/__init__.py", line 2, in <module>
    from .data import (DataReader, Options, get_components_yahoo,
  File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/data.py", line 14, in <module>
    from pandas_datareader.fred import FredReader
  File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/fred.py", line 1, in <module>
    from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'

回答by Nils

A solution withoutchanging any files locally and bypassthe version control of your package manager (pip) is to define is_list_likelike this:

更改本地任何文件并绕过包管理器(pip)的版本控制的解决方案是像这样定义is_list_like

import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like

right before

就在之前

import pandas_datareader as web

Furthermore this problem will be fixed in pandas_datareader version 0.7.0 release.

此外,此问题将在 pandas_datareader 0.7.0 版中修复。

回答by huanggh

I meet this error and I found a method to solve it. My pandas and pandas_datareader versions are 0.23 and 0.6.

我遇到了这个错误,我找到了解决它的方法。我的 pandas 和 pandas_datareader 版本是 0.23 和 0.6。

Python 3.6.5 (default, Apr  1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas_datareader
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/__init__.py", line 2, in <module>
    from .data import (DataReader, Options, get_components_yahoo,
  File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/data.py", line 14, in <module>
    from pandas_datareader.fred import FredReader
  File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/fred.py", line 1, in <module>
    from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'

enter image description here

在此处输入图片说明

Because the is_list_likeis moved to pandas.api.types, I change the fred.py file which is highlighted in the picture. I replace from pandas.core.common import is_list_likewith from pandas.api.types import is_list_like, and it works.

因为is_list_like移到了pandas.api.types,所以我更改了图片中突出显示的fred.py 文件。我代替from pandas.core.common import is_list_likefrom pandas.api.types import is_list_like,和它的作品。

enter image description here

在此处输入图片说明

回答by Addison Lynch

This is due to the fact that is_list_likehas been moved from pandas.core.commonto pandas.api.typesin Pandas 0.23.0. This issue has been repaired hereand will be a part of the Pandas Datareader 0.7.0 release. For now, I would recommend using the dev version of Datareader. Instructions for installing can be found in the documentation.

这是由于这样的事实is_list_like已经从移动pandas.core.commonpandas.api.types在大熊猫0.23.0。此问题已在此处修复,并将成为 Pandas Datareader 0.7.0 版本的一部分。目前,我建议使用 Datareader 的开发版本。安装说明可以在文档中找到。

回答by Rajendra Prasad Taidala

If you are not working with pandas_datareader. you need to check your conda environment data reader is installed or not if not install than you can import this way this.

如果您不使用 pandas_datareader。您需要检查您的 conda 环境数据阅读器是否安装,如果没有安装,您可以通过这种方式导入。

import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader as web

回答by Muhammad Sulman

Edit fred.py file inside /your_installation_path/python2.7/site-packages/pandas_datareader and replace as below:

编辑 /your_installation_path/python2.7/site-packages/pandas_datareader 中的 fred.py 文件并替换如下:

from pandas.core.common import is_list_like #COMMENT IT

从 pandas.core.common 导入 is_list_like #COMMENT IT

from pandas.api.types import is_list_like #ADD

从 pandas.api.types 导入 is_list_like #ADD

回答by Rahul Soshte

In Ubuntu 18.04, using Python 3.6 I resolved the error in the following way.

在 Ubuntu 18.04 中,使用 Python 3.6 我通过以下方式解决了错误。

cd /home/username/.local/lib/python3.6/site-packages/pandas_datareader

cd /home/username/.local/lib/python3.6/site-packages/pandas_datareader

subl fred.py

and I changed the first line of code which was

我改变了第一行代码

from pandas.core.common import is_list_like

to

from pandas.api.types import is_list_like