Search code examples
pythonpandas-datareader

Import "pandas_datareader.data" could not be resolved


I am trying to download financial data using the library pandas_datareader Here is a code that I'm trying to run:

from pandas_datareader import data
import fix_yahoo_finance as yf
yf.pdr_override() 

symbol = 'AMZN'
data_source='google'
start_date = '2010-01-01'
end_date = '2016-01-01'
df = data.get_data_yahoo(symbol, start_date, end_date)
print(df)
df.head()

The error message I got is "Import "pandas_datareader" could not be resolved" and "Import "fix_yahoo_finance" could not be resolved".

I made sure that pandas_datareader is installed and up to date using pip install, but I'm not sure if I installed it to the correct environment.

I'm relatively new to the topic, so any advice or troubleshooting step would be much appreciated!


Solution

  • After searching a bit, I found following:

    1. fix-yahoo-finance is now renamed to yfinance which you can install with:
    pip install yfinance --upgrade --no-cache-dir
    
    1. Install pandas_datareader with:
    pip install pandas-datareader
    
    1. If you are using Python 3.10+, then you will receive distutils error which can be solved with:
    pip install setuptools  
    
    1. According to the GitHub issue,

    yf.pdr_override() is removed already and you will get an error.