Python Forum
WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH
#1
When I run the following code, I get this error. I am not sure what it means or how to correct this error.

import numpy as np
from datetime import datetime
import smtplib
from selenium import webdriver
import os

#For Prediction
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_validate
from sklearn import preprocessing

#For Stock Data
from iexfinance.stocks import get_historical_data

def getStocks(n):
    #Navigating to the Yahoo stock screener
    driver = webdriver.Chrome(
        'PATH TO CHROME DRIVER')
    url = "https://finance.yahoo.com/screener/predefined/aggressive_small_caps?offset=0&count=202"
    driver.get(url)

    #Creating a stock list and iterating through the ticker names on the stock screener list
    stock_list = []
    n += 1
    for i in range(1, n):
        ticker = driver.find_element_by_xpath(
            '//*[@id = "scr-res-table"]/div[2]/table/tbody/tr[' + str(i) + ']/td[1]/a')
        stock_list.append(ticker.text)
    driver.quit()
    
    #Using the stock list to predict the future price of the stock a specificed amount of days
    number = 0
    for i in stock_list:
        print("Number: " + str(number))
        try:
            predictData(i, 5)
        except:
            print("Stock: " + i + " was not predicted")
        number += 1

def sendMessage(text):
    # If you're using Gmail to send the message, you might need to 
    # go into the security settings of your email account and 
    # enable the "Allow less secure apps" option 
    username = "EMAIL"
    password = "PASSWORD"

    vtext = "[email protected]"
    message = text

    msg = """From: %s
    To: %s
    %s""" % (username, vtext, message)

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(username, password)
    server.sendmail(username, vtext, msg)
    server.quit()

    print('Sent')

def predictData(stock, days):
    print(stock)

    start = datetime(2017, 1, 1)
    end = datetime.now()

    #Outputting the Historical data into a .csv for later use
    df = get_historical_data(stock, start=start, end=end, output_format='pandas')
    if os.path.exists('./Exports'):
        csv_name = ('Exports/' + stock + '_Export.csv')
    else:
        os.mkdir("Exports")
        csv_name = ('Exports/' + stock + '_Export.csv')
    df.to_csv(csv_name)
    df['prediction'] = df['close'].shift(-1)
    df.dropna(inplace=True)

    forecast_time = int(days)

    #Predicting the Stock price in the future
    X = np.array(df.drop(['prediction'], 1))
    Y = np.array(df['prediction'])
    X = preprocessing.scale(X)
    X_prediction = X[-forecast_time:]
    X_train, Y_train, Y_test = cross_validation.train_test_split(
        X, Y, test_size=0.5)

    #Performing the Regression on the training data
    clf = LinearRegression()
    clf.fit(X_train, Y_train)
    prediction = (clf.predict(X_prediction))

    last_row = df.tail(1)
    print(last_row['close'])

    #Sending the SMS if the predicted price of the stock is at least 1 greater than the previous closing price
    if (float(prediction[4]) > (float(last_row['close'])) + 1):
        output = ("\n\nStock:" + str(stock) + "\nPrior Close:\n" + str(last_row['close']) + "\n\nPrediction in 1 Day: " + str(
            prediction[0]) + "\nPrediction in 5 Days: " + str(prediction[4]))
        sendMessage(output)

if __name__ == '__main__':
    getStocks(200)
This when run on a Windows 10 machine produces the error.

Output:
FileNotFoundError Traceback (most recent call last) ~\miniconda3\envs\tensorflow-2.1\lib\site-packages\selenium\webdriver\common\service.py in start(self) 75 stderr=self.log_file, ---> 76 stdin=PIPE) 77 except TypeError: ~\miniconda3\envs\tensorflow-2.1\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text) 799 errread, errwrite, --> 800 restore_signals, start_new_session) 801 except: ~\miniconda3\envs\tensorflow-2.1\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session) 1206 os.fspath(cwd) if cwd is not None else None, -> 1207 startupinfo) 1208 finally: FileNotFoundError: [WinError 2] The system cannot find the file specified During handling of the above exception, another exception occurred: WebDriverException Traceback (most recent call last) <ipython-input-1-d737cd6c0180> in <module> 103 104 if __name__ == '__main__': --> 105 getStocks(200) <ipython-input-1-d737cd6c0180> in getStocks(n) 16 #Navigating to the Yahoo stock screener 17 driver = webdriver.Chrome( ---> 18 'PATH TO CHROME DRIVER') 19 url = "https://finance.yahoo.com/screener/predefined/aggressive_small_caps?offset=0&count=202" 20 driver.get(url) ~\miniconda3\envs\tensorflow-2.1\lib\site-packages\selenium\webdriver\chrome\webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive) 71 service_args=service_args, 72 log_path=service_log_path) ---> 73 self.service.start() 74 75 try: ~\miniconda3\envs\tensorflow-2.1\lib\site-packages\selenium\webdriver\common\service.py in start(self) 81 raise WebDriverException( 82 "'%s' executable needs to be in PATH. %s" % ( ---> 83 os.path.basename(self.path), self.start_error_message) 84 ) 85 elif err.errno == errno.EACCES: WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home


I take it that I must download and install a new Chromedriver for Windows 10 (I choose the stable version ) and then put it in my path.

Is that all. I must do? When was this changed? I have similar software before, but never had this situation.

Any help appreciated.

Respectfully,

LZ
Reply
#2
Try whats in this thread https://python-forum.io/thread-25656-pos...#pid109722
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using OpenCV and image path is invalid AudunNilsen 5 545 Mar-18-2024, 05:28 PM
Last Post: snippsat
  Path Planning prachibhanaria 0 298 Jan-23-2024, 10:11 AM
Last Post: prachibhanaria
  Create dual folder on different path/drive based on the date agmoraojr 2 431 Jan-21-2024, 10:02 AM
Last Post: snippsat
  working directory if using windows path-variable chitarup 2 724 Nov-28-2023, 11:36 PM
Last Post: chitarup
  Can't Find Path hatflyer 8 1,043 Oct-30-2023, 06:17 AM
Last Post: Gribouillis
  os.path.join() 'NoneType' confusion gowb0w 11 1,539 Sep-22-2023, 11:13 PM
Last Post: deanhystad
  Why wont this path work one way, but will the other way? cubangt 2 668 Sep-01-2023, 04:14 PM
Last Post: cubangt
Bug tkinter.TclError: bad window path name "!button" V1ber 2 777 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Boustrophedon path planning proteca 0 647 Jun-24-2023, 02:45 PM
Last Post: proteca
  does not save in other path than opened files before icode 3 897 Jun-23-2023, 07:25 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020