import pandas_datareader gives ImportError: cannot import name 'is_list_like'
Asked Answered
M

6

58

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

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'
Myology answered 17/5, 2018 at 15:10 Comment(5)
what is your pandas version?Scapula
pandas version is 0.23.0Myology
It looks like your version of pandas_datareader is not compatible with brand new Pandas 0.23Scapula
Quite possible. Let me purge it and install an older version. Then I will check again thanks.Myology
@MaxU working well with 0.21.0. ThanksMyology
N
63

I meet this error and I found a method to solve it. My pandas and pandas_datareader versions are 0.23 and 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_like is 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_like with from pandas.api.types import is_list_like, and it works.

enter image description here

Nocturne answered 18/5, 2018 at 16:15 Comment(6)
You can put pd.core.common.is_list_like = pd.api.types.is_list_like before you import pandas_datareader so you don't need to edit fred.py.Hake
I installed an earlier version of Pandas and it is working fine. So if someone wants to use pandas 0.23 then this seems to be correct method.Myology
This work for as well, all I did was open the file and change the line 1 to this: from pandas.api.types import is_list_like the thing that I don't understand is that it seems that this was patch a while ago, and the latest library has this, which is what I have, does not include this patch. anyway, thanks for tip.Carlist
@Hake in which file did you place that line?Tuchman
@Tuchman I put it in my python script just before I write import pandas_datareader.Hake
Modifying a library source is definitely a workaround that should be avoided. If you modify the highlighted path, you'll break pandas for the system-wide python3.6... something you really want to avoid. Ps. downgrading pandas to 0.23.0 with pandas_reader 0.6 didn't work for me.Oleum
D
97

A solution without changing any files locally and bypass the version control of your package manager (pip) is to define is_list_like like this:

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.

Downward answered 21/6, 2018 at 13:45 Comment(2)
This should be the accepted answer because it doesn't need to change any files to work.Cholecystitis
agreed, 1 line of code fixes the problem until datareader 0.7 is readyBer
N
63

I meet this error and I found a method to solve it. My pandas and pandas_datareader versions are 0.23 and 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_like is 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_like with from pandas.api.types import is_list_like, and it works.

enter image description here

Nocturne answered 18/5, 2018 at 16:15 Comment(6)
You can put pd.core.common.is_list_like = pd.api.types.is_list_like before you import pandas_datareader so you don't need to edit fred.py.Hake
I installed an earlier version of Pandas and it is working fine. So if someone wants to use pandas 0.23 then this seems to be correct method.Myology
This work for as well, all I did was open the file and change the line 1 to this: from pandas.api.types import is_list_like the thing that I don't understand is that it seems that this was patch a while ago, and the latest library has this, which is what I have, does not include this patch. anyway, thanks for tip.Carlist
@Hake in which file did you place that line?Tuchman
@Tuchman I put it in my python script just before I write import pandas_datareader.Hake
Modifying a library source is definitely a workaround that should be avoided. If you modify the highlighted path, you'll break pandas for the system-wide python3.6... something you really want to avoid. Ps. downgrading pandas to 0.23.0 with pandas_reader 0.6 didn't work for me.Oleum
K
11

This is due to the fact that is_list_like has been moved from pandas.core.common to pandas.api.types in Pandas 0.23.0. This issue has been repaired here and 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.

Kelter answered 18/5, 2018 at 23:32 Comment(0)
C
4

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.

import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader as web
Culinarian answered 8/8, 2018 at 2:14 Comment(0)
M
1

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

from pandas.core.common import is_list_like #COMMENT IT

from pandas.api.types import is_list_like #ADD

Meaganmeager answered 3/6, 2018 at 14:9 Comment(0)
D
0

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

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
Detrimental answered 21/6, 2018 at 13:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.