Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import pandas_datareader gives ImportError: cannot import name 'is_list_like'

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'
like image 750
Raj Avatar asked May 17 '18 15:05

Raj


5 Answers

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.

like image 180
Nils Avatar answered Nov 09 '22 17:11

Nils


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

like image 63
huanggh Avatar answered Nov 09 '22 18:11

huanggh


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.

like image 11
Addison Lynch Avatar answered Nov 09 '22 16:11

Addison Lynch


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
like image 4
Rajendra Prasad Taidala Avatar answered Nov 09 '22 17:11

Rajendra Prasad Taidala


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

like image 1
Muhammad Sulman Avatar answered Nov 09 '22 18:11

Muhammad Sulman