1
votes

I am fairly new to python and right now, I am currently learning python through Al Sweigart's Automate the boring stuff with Python.

Right now, I want to open a Firefox by using webdriver. When I run the code:

from selenium import webdriver

I get no error. However, after running:

browswer=webdriver.Firefox()

I get the following error message.

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

During handling of the above exception, another exception occurred:

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

Now, I have already installed geckodriver and I have been scrolling through google to try to find the solution. So far, I have tried manually adding geckodriver to /usr/local/bin. I have also tried running:

brew install geckodriver 

on terminal. It suggested me to try overwriting geckodriver, so brew installed geckodriver on /usr/local/Cellar/geckodriver/0.21.0/bin/geckodriver.

I've ran

sudo nano /etc/paths 

to see the list of my paths, and here are the list:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/Cellar/geckodriver/0.21.0/bin/geckodriver

So I do not know why python is telling me geckodriver executable needs to be in PATH when it is already there.

Could someone help me out?

2
Thank you @Ratmir Asanov for the reply. If I uninstall geckodriver, I will go back to square one. Does anyone have any idea how to copy geckodriver into my /usr/local/bin file, so I can run without writing down the path everytime? - jyabjyabs
"It suggested me to try overwriting geckodriver" What was the exact output of the command? - bfontaine

2 Answers

0
votes

You can place the geckodriver in the Python folder. I did that when I got the same error and after I place the geckodriver in the Python folder, everything was working. I have included an image as reference. geckodriver in Python folder

0
votes

I had the exact same problem as OP on Mac OS. What solved it for me is to copy geckodriver into the python path.

Specifically in terminal

which geckdriver

gives the following path

/usr/local/bin/geckodriver

and

which python

gives the path for Python

/Users/USERNAME/anaconda3/bin/python

Then I copied the geckodriver into the python bin

cd /usr/local/bin/
cp geckodriver /Users/USERNAME/anaconda3/bin/

And I was able to call geckodriver from Python.