ModuleNotFoundError: No module named 'yfinance' - Importing Yahoo finance & Financials to Python
Asked Answered
A

7

7

I'm using Mac OS and receiving an error when doing the following:

import pandas as pd
import yfinance as yf
from yahoofinancials import YahooFinancials

ModuleNotFoundError: No module named 'yfinance'

I've checked pip is installed to the latest version & I've done pip list and yfinance is in there.

I have also checked with:

pip show yfinance
Name: yfinance
Version: 0.1.70
Summary: Download market data from Yahoo! Finance API
Home-page: https://github.com/ranaroussi/yfinance
Author: Ran Aroussi
Author-email: [email protected]
License: Apache
Location: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages
Requires: lxml, multitasking, numpy, pandas, requests
Required-by: 
MacBook-Air:~ User$ 

So it's installed and its path is that of Python3 the latest python.

I'd really appreciate any suggestions!

Thanks

[EDIT]

I'm running Spyder from the default Spyder environment.

Ardenardency answered 23/2, 2022 at 16:5 Comment(5)
How are you running your script? Have you verified that the same environment you're running script in is the one you're installing packages to?Claudiaclaudian
I'm running script from the default spyder environmentArdenardency
Looks like this post is relevant, does that help?Claudiaclaudian
You have missing dependencies! # Mandatory: nbconvert >=4.0 : None (NOK) Please install them to avoid this message. Note: Spyder could work without some of these dependencies, however to have a smooth experience when using Spyder we strongly recommend you to install all the listed missing dependencies. I updated it using the PATHMANAGE but now i have this following error: Failing to install these dependencies might result in bugs. Please be sure that any found bugs are not the direct result of missing dependencies, prior to reporting a new issue.Ardenardency
Above is the error after I have used the python manager to link to the library. ><Ardenardency
C
9

put this one at the beginning

!pip install yfinance
Copt answered 24/2, 2022 at 7:37 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Lassa
M
2

I had the same error on Linux. Which rectified by forcing reinstall of the package by the following code.

python -m pip install -U --force-reinstall yfinance 

=

Maffick answered 5/5, 2022 at 7:0 Comment(1)
Many thanks. This worked for me on MacOS 14.1 Sonoma running Python 3.12.1.Occiput
F
1

To install yfinance package with pip:

pip install -i https://pypi.anaconda.org/ranaroussi/simple finance

To install yfinance package with conda:

conda install -c ranaroussi yfinance
Flagler answered 23/2, 2022 at 17:7 Comment(1)
They said they installed it with pip, what exactly is new or different about this answer?Claudiaclaudian
T
0

enter image description here

Please check the settings in Python Interpreter and make sure the package yfinance has been installed there. If yfinance cannot be found, please add the package there.

Trinatte answered 21/2, 2023 at 2:3 Comment(0)
R
0

Install yfinance

!pip install yfinance

Import the modules if you have already installed

import pandas_datareader as pdr

import pandas as pd

from datetime import datetime

import yfinance as yf

## Download 

df_tesla=yf.download('TSLA')

df_tesla

All works fine then, it worked for me.

Robeson answered 9/8, 2023 at 10:29 Comment(0)
E
0
python -m pip install -U --force-reinstall yfinance 

Really worked for me but only after I ran that and then restarted my IDE and all open consoles. I really believe that restarting your console is important.

Exceeding answered 23/3 at 9:53 Comment(0)
T
0

I solved it with these commands:

  1. sudo apt get update
  2. sudo apt install python3-pip
  3. pip install yfinance
Tamishatamma answered 25/4 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.