问题
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?
回答1:
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"
回答2:
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.
来源:https://stackoverflow.com/questions/57104639/how-to-fix-importerror-cannot-import-name-stringio