简体   繁体   中英

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?

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM