Nenad Nenad - 1 year ago 87
Python Question

Error while importing selenium on Ubuntu

So as it says in the title I have a problem with importing Selenium module on my Ubuntu laptop. On my Windows pc everything goes fine with basic Selenium code:

from selenium import webdriver
driver = webdriver.Firefox()

but when I try to do that on my Ubuntu machine I get an error that is basically saying:

os.path.basename(self.path), self.start_error_message)
selenium.common.exception.WebDriverException: Message:'geckodriver'executable needs to be in PATH.

Has anyone encoutered this problem and if yes does anyone know how to fix it?

Answer Source

An easy way to fix this is to download the driver from here:

Method 1: Adding geckodriver to existing path folder

Unzip the file and copy the "geckodriver" executable to "/usr/bin" using:

cd /folder/containing/geckodriver
sudo cp geckodriver /usr/bin

Method 2: Adding custom geckodriver location to path

You can also add the driver in your system path temporarily with:

export PATH=$PATH:/path/to/geckodriver

For a permanent solution, you can edit your bash profile with:

gedit ~/.profile

Then find the PATH line and modify it to look more like this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download