64

I'm running a simple example of selenium on Linux:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("something")

and get an error:

FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

How to fix it?

$ python
Python 3.5.2 (default, Jun 28 2016, 08:46:01) 
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>> from selenium.webdriver.common.keys import Keys
>>> 
SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Meji
  • 977
  • 2
  • 8
  • 10
  • In Java I would neet to set the system property of the gecko driver, might be what you need to do as well, but I don't know Python that well. What I use in Java: `System.setProperty("webdriver.gecko.driver", "path/to/driver");` – Thibstars Oct 28 '16 at 15:01

9 Answers9

55

Downloading geckodriver

The geckodriver executable can be downloaded here.

Python3 venv

Download the geckodriver executable from the above link and extract it to env/bin/ to make it accessible to only the virtual environment.

In your python code, you will now be able to do the following:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get("https://stackoverflow.com/")

Linux

If you would like to make it available system wide, download the geckodriver executable from the above link and extract it to /usr/bin/ (or anything inside of your $PATH)

Windows

Note: this needs a windows user to test and confirm

Download geckodriver from the above link and extract it to C:\Windows\System32\ (or anything inside your Path environment variable).

Mac OS X

Note: I took this from Vincent van Leeuwen's answer in this very question. Putting it here for the sake of lumping everything in one answer

To make geckodriver available system wide, open up your Terminal App and perform the following command:

brew install geckodriver

More Info

More info on selenium can be found here:

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.

Failure to observe this step will give you an error selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Rdesmond
  • 1,201
  • 10
  • 30
  • 1
    Can you update your answer to include the info in case the link(s) go down? – OJ7 Jul 13 '18 at 01:33
  • @Suspended could you clarify what you downloaded? I was able to download both Windows and Linux binaries from the link in the answer – Rdesmond Dec 15 '20 at 03:10
10

I faced same issue in Linux. I used below steps to fix that Error.

cd /bin

# Check on https://github.com/mozilla/geckodriver/releases for the latest release
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux32.tar.gz
tar -xvzf geckodriver-v0.24.0-linux32.tar.gz
rm geckodriver-v0.24.0-linux32.tar.gz
chmod +x geckodriver
export PATH=$PATH:/bin/geckodriver

geckodriver --version

Note : I tried with latest version geckodriver-v0.26.0 but it not working for me, That's Why I installed the old version v0.24.0

Sri
  • 101
  • 1
  • 4
9

Linux: You can install "sudo apt install firefox-geckodriver"

David Viana
  • 516
  • 2
  • 8
  • 17
6

Selenium requires geckodriver to interface with Firefox. Here's how to install geckodriver:

  1. Download geckodriver from https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz (or if you need the 32 bit version, go to https://github.com/mozilla/geckodriver/releases to see more download options)
  2. Extract the file into your Downloads folder
  3. Open a console and run sudo mv ~/Downloads/geckodriver /usr/bin
Paul Chris Jones
  • 2,646
  • 1
  • 23
  • 21
2

Mac OSX:

Firefox? brew install geckodriver

Chrome? brew install chromedriver

jasonleonhard
  • 12,047
  • 89
  • 66
Vincent van Leeuwen
  • 681
  • 1
  • 9
  • 17
1

On linux, you can install Homebrew and then brew install geckodriver through it

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
brew install geckodriver

or by installing Nix

curl https://nixos.org/nix/install | sh
nix install geckodriver

but adding another package manager to your system might be a bad idea.

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
1

Mac OSX:

Firefox? brew install geckodriver

Chrome? brew install chromedriver

Choose one:

driver = webdriver.Firefox()   # brew install geckodriver
driver = webdriver.Chrome()    # brew install chromedriver
jasonleonhard
  • 12,047
  • 89
  • 66
1

Here is the correct way:

sudo apt install firefox-geckodriver

You do not need manual installations.

ar2015
  • 5,558
  • 8
  • 53
  • 110
  • 1
    Does not help using latest Debian/Ubuntu: E: Unable to locate package firefox-geckodriver – Freude Aug 11 '22 at 01:33
0

There is a python package that autoinstalls it crossplattform, no need for users to manually install it: https://pypi.org/project/geckodriver-autoinstaller/

juliushuck
  • 1,398
  • 1
  • 11
  • 25