Search code examples
pythonseleniumfirefoxselenium-webdriverselenium-chromedriver

Selenium in Python on Mac - Geckodriver executable needs to be in PATH


I'm new to programming and started with Python about 2 months ago and am going over Sweigart's Automate the Boring Stuff with Python text. I'm using Spyder 3 and already installed the selenium module and the Firefox browser. I used the following code in python file

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://inventwithpython.com')

I get this error:

Message: 'geckodriver' executable needs to be in PATH.

I've downloaded geckodriver.exe in addition to going into terminal and installing it using

brew install geckodriver

Oddly enough, if I go into terminal and type "python" and then put the code in, it works, but not when I run the file in Spyder. Where do I need to put the geckodriver.exe file for it to work? I've tried putting it in various folders (same folder as the python file, same folder as the webdriver file, in the user bin, and so on) but I get the same error

I've looked at similar questions but can't seem to find something that works. I've also tried with Chrome but I get the same error but with chromedriver.

which geckodriver

yields /usr/local/bin/geckodriver

I'm also on a Mac, so file paths are a little more difficult for me than on windows.


Solution

  • SOLVED: I placed the geckodriver exe in /Users/sethkillian/anaconda/bin and now it works from Spyder with no problem. Thanks for the help!