Search code examples
pythoncondayfinance

Import yfinance could not be resolved


I'm trying to write a program that gets stock data using yfinance. I wrote:

import yfinance as yf

and got the warning:

import "yfinance" could not be resolved 

Tried importing yfinance using pip, pip3, and conda, as well as pip install yfinance --upgrade --no-cache-dir, which I've seen some people recommend. None of it worked.

Looking on StackOverflow,it seems like one other person had the same problem but never found a solution. Any ideas? Or, if not, are there any other free ways to get live stock data into a program? It doesn't have to be Python.

If it helps, I'm on a Mac M1 running a conda virtual environment inside VSCode.


Solution

  • If you're using an IDE like vs code, try running it without that.

    If you are on windows, open command prompt and navigate to the directory of your Python file using cd. Then type either python3 file.py or python file.py (replacing file with your actual file name of course).

    If that doesn't work, something else is wrong with your Python installation or pip. I would suggest reinstalling them.