2

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: connor@exceleri.com
License: MIT
Location: c:\users\user\stockspredct\lib\site-packages
Requires: beautifulsoup4, pytz
Required-by:

Please help me how I can fix this error

buran
  • 13,682
  • 10
  • 36
  • 61
Navdissenyo
  • 23
  • 1
  • 3
  • do you have multiple versions of python installed? (possibly the version that pip has installed to isn't the version being used when you run the code?) – Sylvansight May 16 '21 at 16:34
  • check this [threat](https://stackoverflow.com/questions/338768/python-error-importerror-no-module-named) on stackoverlow.This should help you – Kacper Remzak May 16 '21 at 16:45

4 Answers4

1

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.

  • yes, you are right, I installed it in Virtual Environment and Check I have activated my virtual environment before running it. But getting the same error massage! – Navdissenyo May 20 '21 at 09:08
  • The other way you can debug this is, try uninstalling numpy and run your code and then again install numpy the same way you are installing yahoofinancials. There maybe multiple versions of python or pip. – Akshay Goyal May 20 '21 at 11:02
1

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

samuelhogg
  • 41
  • 3
0

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

AnoopDixit
  • 209
  • 2
  • 6
0

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.

ASH
  • 20,759
  • 19
  • 87
  • 200