How do I install Geckodriver?

130.4k views Asked by At

I am attempting to work with Selenium in Python. However, I do not know what to do given the below from https://pypi.python.org/pypi/selenium

Selenium requires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver, which needs to be installed before the below examples can be run. Make sure it’s in your PATH, e.g., place it in /usr/bin or /usr/local/bin.

I am running windows 7 32bit. I found geckodriver here: https://github.com/mozilla/geckodriver/releases

I have mostly used the Anaconda distribution of Python to work with excel so I do not know what is a "PATH"

Thanks,

UPDATE:

I updated the PATH as shown in the comments. Here is the full error traceback.

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\user1>python

Python 3.5.2 |Anaconda 4.2.0 (32-bit)| (default, Jul 5 2016, 11:45:57) [MSC v.1 900 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

from selenium import webdriver
driver = webdriver.Firefox()

Traceback (most recent call last):

File "", line 1, in

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\webdriver.py", li ne 80, in init self.binary, timeout)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\extension_connect ion.py", line 52, in init self.binary.launch_browser(self.profile, timeout=timeout)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py ", line 67, in launch_browser self._start_from_profile_path(self.profile.path)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py ", line 90, in _start_from_profile_path env=self._firefox_env)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py", line 947, in init restore_signals, start_new_session)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py", line 1224, in _execute_child startupinfo)

FileNotFoundError: [WinError 2] The system cannot find the file specified

11

There are 11 answers

9
jmunsch On

Some options, choose 1:

  • Move the exe file to a folder in your PATH environment variable.
  • Update PATH to have the directory that contains the exe.
  • Explicitly override os.environ["webdriver.gecko.driver"]

basically drag and drop the geckodriver someplace where you have your executables, you should then be able to open the command line and use it.

/bin on linux, and C:\Program Files

see:

specifically the explanations on how the driver is seen, where it can be put ,and how to modify the way selenium finds it.

2
Charles Santos On

There is an easy way to install Geckodriver:

  1. Install webdrivermanager with pip

    pip install webdrivermanager

  2. Install the driver for Firefox and Chrome

    webdrivermanager firefox chrome --linkpath /usr/local/bin

  3. Or install the driver only for Firefox

    webdrivermanager firefox --linkpath /usr/local/bin

  4. Or install the driver only for Chrome

    webdrivermanager chrome --linkpath /usr/local/bin

0
CodingMatters On

to avoid links becoming out of date, please refer the soource. https://github.com/mozilla/geckodriver follow the readme instructions to the "Downloads" > "Releases" link.

1
Edward Knueppel Jr. On
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))

First pip install selenium and webdriver-manager.

This code will install the latest driver and cache it. It will also use a Service object to load the webdriver, which is important because executable_path is deprecated.

0
tfv On

Meanwhile for Win10 you can simply use

from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get("https://www.google.com")

This will download the geckodrive prior to its first use and store it at the appropriate location. No need to set any paths explicitly.

2
Iman On

The easiest way if you are on windows:

driver = webdriver.Firefox(executable_path=r'[Your path]\geckodriver.exe')

Example:

driver = webdriver.Firefox(executable_path=r'D:\geckodriver.exe')
0
kip2 On

If you're on macOS/Apple, you can use Homebrew: brew install geckodriver

See this related question

0
jeppoo1 On

For me this worked (Windows 10, Firefox browser):

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\......YOUR_PATH.......\geckodriver.exe')
driver.get('http://EXAMPLE_URL.com')
0
NoobCoder On

For Python 3 - Selenium plus webdriver for Firefox;

  1. Open up Command line
  2. Enter Pip install -U Selenium (The -U will upgrade it to the latest Selenium version.) This example selenium is already installed

  3. Go to https://github.com/mozilla/geckodriver/releases

  4. At the time of writing I chose the latest version which was simply the version listed at the top of the page. For me it was v0.24.0.

  5. Scroll down to assets and then click and download the correct driver. For windows it will be a zip file. Most likely 64bit. Download the webdriver by clicking on the link 5.Right click on the downloaded file and unzip the file.

  6. Copy and paste the file to somewhere in your python directory. e.g. If I installed Python in C:\Python\Python37 I would paste the file in there so gecko would be located in C:\Python\Python37\geckodriver-v0.24.0-win64

Copying the file path of the geckodriver

  1. Inside that folder you just copied will be the geckodriver.exe

  2. In Windows 10, click the "windows" button and search "environment variables" Find environment variables OR find it using these instructions; https://www.computerhope.com/issues/ch000549.htm

  3. Click on the "environment variables" box at the bottom right hand corner.

  4. In the bottom box "System Variables" highlight the "Path" variable like so Adding environment variable Path

  5. Press edit and then add the entry at the bottom of the list. Copy and paste the location where the geckodriver.exe file lives. For me it was C:\Python\Python37\geckodriver-v0.24.0-win64 (or where you copied the file in step 6) Adding gecko to the windows PATH

6
hafiz031 On

For Linux/Ubuntu:

The following simple installation worked for me:

sudo apt install firefox-geckodriver

No additional driver installation was required.

Reference: https://github.com/timgrossmann/InstaPy/issues/5282#issuecomment-666283451

For windows:

Follow the instructions here: http://www.learningaboutelectronics.com/Articles/How-to-install-geckodriver-Python-windows.php

0
jayesh On
  1. You can download the geckodriver
  2. unzip it
  3. Copy that .exe file and put your into python parent folder (e.g., C:\Python34)
  4. write your scripts.

It will execute successfully.