Pandas-datareader: Cannot import name 'StringIO' from 'pandas.compat'

Created on 21 Jul 2019  路  14Comments  路  Source: pydata/pandas-datareader

Conflict with Pandas 0.25.0 and pandas-datareader 0.7.0.
On Python 3.7.3

import pandas_datareader as pdr

raises exception:
/usr/local/lib/python3.7/dist-packages/pandas_datareader/base.py in
9 from pandas import read_csv, concat
10 from pandas.io.common import urlencode
---> 11 from pandas.compat import StringIO, bytes_to_str
12
13 from pandas_datareader._utils import (RemoteDataError, SymbolWarning,

ImportError: cannot import name 'StringIO' from 'pandas.compat' (/usr/local/lib/python3.7/dist-packages/pandas/compat/__init__.py)

Most helpful comment

Try pip install pandas-datareader --upgrade

All 14 comments

Facing same error, even tho it just warns about StringIO, which, apparently is in IO, neither StringIO or bytes_to_str are in compat, and there are a lot of files calling it from there.
After changing the sublibrary in all those files and coding the bytes_to_str function, there are still more sublibraries missing in compat, at least lmap.

Tested in two different machines, windows and linux.

Hope we can find a fix soon.

Work around is to roll back to prior version of Pandas 0.24.2
pip3 install --upgrade pandas==0.24.2

This has been repaired in #653 and will be merged soon. The above workaround will solve the issue until then.

This change has been merged. Re-install dev version from git repo to update.

Same library change also causes bug with:
from pandas.compat import bytes_to_str

Have re-installed Pandas 0.25.0 and pandas-datareader from dev (0.7.0+55.g874b385).
I can confirm the original error is no longer raised, many thanks.
But as @ricpruss mentions above we now get this exception:

/usr/local/lib/python3.7/dist-packages/pandas_datareader/base.py in
10 from pandas import read_csv, concat
11 from pandas.io.common import urlencode
---> 12 from pandas.compat import bytes_to_str
13
14 from pandas_datareader._utils import (RemoteDataError, SymbolWarning,

ImportError: cannot import name 'bytes_to_str' from 'pandas.compat' (/usr/local/lib/python3.7/dist-packages/pandas/compat/__init__.py)

Closing this issue. Raising new issue for the similar error with bytes_to_str.

Work around is to roll back to prior version of Pandas 0.24.2
pip3 install --upgrade pandas==0.24.2

pipenv install pandas~=0.24.2

I have pushed 0.7.1 to PyPI which should fix this issue.

Thanks, but I can still reproduce the problem with Python 3.6.8 on Ubuntu 18.04:

$ python3 -m venv venv
$ . venv/bin/activate
$ pip3 install pandas-datareader
Collecting pandas-datareader

# output omitted for brevity

Installing collected packages: numpy, pytz, six, python-dateutil, pandas, idna, chardet, urllib3, certifi, requests, wrapt, lxml, pandas-datareader
Successfully installed certifi-2019.6.16 chardet-3.0.4 idna-2.8 lxml-4.4.0 numpy-1.17.0 pandas-0.25.0 pandas-datareader-0.7.1 python-dateutil-2.8.0 pytz-2019.1 requests-2.22.0 six-1.12.0 urllib3-1.25.3 wrapt-1.11.2

$ venv/bin/python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas_datareader as pdr

# some traceback skipped for brevity

  File "/home/foo/testdir/venv/lib/python3.6/site-packages/pandas_datareader/base.py", line 11, in <module>
    from pandas.compat import StringIO, bytes_to_str
ImportError: cannot import name 'StringIO'
>>>

Thanks very much, reinstall pandas by using "pip3 install --upgrade pandas==0.24.2" solved the problem.

@benbendemo if you download the latest release of pandas datareader (Where compatibility issues have been repaired) you will be able to use pandas >= 0.25.0.

@addisonlynch Thanks for the suggestion, i just uninstall pandas then reinstall pandas 0.25.0 version and found the issue still occurs.I guess i didn't understand "download the latest release of pandas datareader"'s meaning, could you give some more detail instruction?

Try pip install pandas-datareader --upgrade

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jalanwilliams picture jalanwilliams  路  8Comments

nithints picture nithints  路  7Comments

prateek2029 picture prateek2029  路  6Comments

amoriello picture amoriello  路  5Comments

paintdog picture paintdog  路  7Comments