Python no module named 'yahoofinancials'

Question:

I write this code:

import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from yahoofinancials import YahooFinancials


yahoo_finance = YahooFinancials(str(stock))
stats=(yahoo_finance.get_historical_price_data("2010-01-01", "2021-04-30", "daily"))

I am already install yahoo-finance1.4.0, yahoofinancials1.6 , yfinance0.1.59 anslo try this

Enter the following four lines in sequence, and execute once for each line:

pip install yahoo-finance
 
git clone git://github.com/lukaszbanasiak/yahoo-finance.git
 
cd yahoo-finance
 
python setup.py install

But still, it’s show error "No module named ‘yahoofinancials’"

I already check this code ">pip show yahoofinancials" and get this info

Name: yahoofinancials
Version: 1.6
Summary: A powerful financial data module used for pulling both fundamental and technical data from Yahoo Finance
Home-page: https://github.com/JECSand/yahoofinancials
Author: Connor Sanders
Author-email: [email protected]
License: MIT
Location: c:usersuserstockspredctlibsite-packages
Requires: beautifulsoup4, pytz
Required-by:

Please help me how I can fix this error

Asked By: Navdissenyo

||

Answers:

It should work the way you are using it. The possible issue may be the environmental change. By looking at the location of the yahoofinancials library in pip, I think you installed it in Virtual Environment and maybe your other libraries are in your global environment. Check if you have activated your virtual environment or try installing yahoofinancials in the global environment.

Answered By: Akshay Goyal

I installed everything as above (incl beautifulsoup4 and pytz) and got the same error message.

I amended the code slightly and I was getting no error messages.

import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from yahoofinancials import YahooFinancials

stock = ['AAPL']
yahoo_finance = YahooFinancials(stock)
stats = (yahoo_finance.get_historical_price_data("2010-01-01", "2021-04-30", "daily"))

Regards Samuel

Answered By: samuelhogg

Installation – yahoofinancials runs on Python 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7.

Details are at – [https://pypi.org/project/yahoofinancials/][1]

The package depends on beautifulsoup4 and pytz to work.

Installation using pip:

Linux/Mac:

$ pip install yahoofinancials


Windows (If python doesn’t work for you in cmd, try running the following command with just py):

python -m pip install yahoofinancials


Installation using github (Mac/Linux):

$ git clone https://github.com/JECSand/yahoofinancials.git

$ cd yahoofinancials

$ python setup.py install

Answered By: AnoopDixit

This may be another way to do what you want to do.

import pandas as pd  
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.optimize as sco
import datetime as dt
import math
from datetime import datetime, timedelta
from pandas_datareader import data as wb
from sklearn.cluster import KMeans
np.random.seed(777)


start = '2018-06-30'
end = '2020-06-30'
# N = 90
# start = datetime.now() - timedelta(days=N)
# end = dt.datetime.today()



tickers = ['AXP','AAPL','BA','CAT','CSCO','CVX','XOM','GS','HD','IBM','INTC','JNJ','KO','JPM','MCD','MMM','MRK','MSFT','NKE','PFE','PG','TRV','UNH','RTX','VZ','V','WBA','WMT','DIS','DOW']

thelen = len(tickers)

price_data = []
for ticker in tickers:
    prices = wb.DataReader(ticker, start = start, end = end, data_source='yahoo')[['Adj Close']]
    price_data.append(prices.assign(ticker=ticker)[['ticker', 'Adj Close']])

df = pd.concat(price_data)
df.dtypes
df.head()
df.shape

pd.set_option('display.max_columns', 500)

df = df.reset_index()
df = df.set_index('Date')
table = df.pivot(columns='ticker')
# By specifying col[1] in below list comprehension
# You can select the stock names under multi-level column
table.columns = [col[1] for col in table.columns]
table.head()

Output:

enter image description here

Etc., etc., etc.

Add and remove tickers as needed.

Answered By: ASH

There is an issue at the GitHub project:

https://github.com/JECSand/yahoofinancials/issues/105

Answered By: Alex
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.