Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "ImportError: cannot import name 'StringIO'"

python version is 3.6.6 and pandas_datareader version is 0.7.0

when i import pandas_datareader, an error occurs like below.

C:\PycharmProjects\Demo\venv\Scripts\python.exe C:/PycharmProjects/Demo/stock.py
Traceback (most recent call last):
  File "C:/PycharmProjects/Demo/stock.py", line 3, in <module>
    import pandas_datareader as wb
  File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
    from .data import (DataReader, Options, get_components_yahoo,
  File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
    from pandas_datareader.av.forex import AVForexReader
  File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
    from pandas_datareader.base import _BaseReader
  File "C:\PycharmProjects\Demo\venv\lib\site-packages\pandas_datareader\base.py", line 11, in <module>
    from pandas.compat import StringIO, bytes_to_str
ImportError: cannot import name 'StringIO'

can somebody help me?

like image 433
김장환 Avatar asked Jul 19 '19 02:07

김장환


2 Answers

The problem is pandas 0.25.0 has removed pandas.compat. So go back to 0.24.2

pip install "pandas<0.25.0"

or

pipenv install "pandas<0.25.0"
like image 113
Ric Pruss Avatar answered Nov 12 '22 00:11

Ric Pruss


I ran into the same issue with Python3.6 and Python3.7

Downgraded, and it works fine on Python2.7 Also, saw a comment above that Python3.5 works.

like image 27
Mirror Mirage Avatar answered Nov 12 '22 01:11

Mirror Mirage