2

I'm working through "Automate the Boring Stuff with Python" and am running Python 3.6 with a Mac running OS X v. 10.9.5. My version of Firefox is 50.0.

Whenever I type in (per the instructions in chapter 11):

>>> from selenium import webdriver
>>> browser = webdriver.Firefox()

I get the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1326, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    browser = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

I have searched this error on this site and others, but most of the solutions offered are Windows-specific (including the post referenced in the comment below), or do not seem to work on my Mac machine when applied.

Any suggestions on what I should do?

Please keep in mind that I'm a total novice, and so less than familiar with the terminal. Thank you in advance for your help.

9
  • 1
    Possible duplicate of Selenium using Python - Geckodriver executable needs to be in PATH Commented Dec 29, 2016 at 18:51
  • As I mentioned in my post, I did check on this website for previous posts on the topic, and tried the solutions offered on the post your reference, but did not have any success with them. The post referenced was from a Windows user, whereas I'm using Mac. Furthermore, the posting instructions in that thread explicitly requested posters post answers rather than requests for clarification or additional questions. Commented Dec 29, 2016 at 19:21
  • 1
    Did you try one of the comments? "On Mac: brew install geckodriver"? Commented Dec 29, 2016 at 19:23
  • If that doesn't work, it's best you continue the discussion on that page with the author of the question. This can be marked as an exact duplicate Commented Dec 29, 2016 at 19:26
  • Yes, I did try that, and got the error: -bash: brew: command not found The OP on the other thread was running Windows and I'm running Mac. How is it an exact duplicate? Commented Dec 29, 2016 at 19:34

2 Answers 2

3

I delved into the source code for webdriver and the Firefox driver: I had to give the Firefox() constructor a direct path to the geckodriver binary, like

self.browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
Sign up to request clarification or add additional context in comments.

1 Comment

Firefox launches, but throws a NameError: name 'self' is not defined'. I removed 'self' and ran the rest of the command, which launched firefox. browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
0

Thanks all for your replies.

Per the comments, installing Homebrew and running the

brew install geckodriver

command did not alone solve the problem. Restarting Terminal also didn't solve things.

I dug around on a few other posts, and tried opening the /usr/bin and /usr/local/bin files through the Mac Finder, and manually copied the geckodriver file into the folder. The first time I entered:

browser = webdriver.Firefox()

into the Python IDLE, I got the following warning/exceptions:

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x101a960b8>>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 173, in __del__
    self.stop()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 145, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x1071b3eb8>>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 173, in __del__
    self.stop()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 145, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

but the browser opened. When I ran it again, I was able to follow along as in the book without any errors or exceptions.

It seems that this has worked. However, it feels wrong to have done all this through the Mac finder rather than Terminal. I'm still very new to all this, so if there's anything I did that will damage my system, I'd appreciate any pointers. Thanks for your help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.