Unknown error: Chrome failed to start: exited abnormally

Solution 1:

For Linux :

Start the Display before start the Chrome. for more info click here

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 800))  
display.start()
driver = webdriver.Chrome()

Solution 2:

To help debug this problem you can use the service_log_path and service_args arguments to the selenium webdriver to see output from the chromedriver:

service_log_path = "{}/chromedriver.log".format(outputdir)
service_args = ['--verbose']
driver = webdriver.Chrome('/path/to/chromedriver',
        service_args=service_args,
        service_log_path=service_log_path)

I was getting this same exception message and found two ways to get past it; I'm not sure if the OP's problem is the same, but if not, the chromedriver log will hopefully help. Looking at my log, I discovered that the chromedriver (I tried 2.9 down to 2.6 while trying to fix this problem) decides which browser to run in a very unexpected way. In the directory where my chromedriver is located I have these files:

$ ls -l /path/to/
-rwx------  1 pjh grad_cs 5503600 Feb  3 00:07 chromedriver-2.9
drwxr-xr-x  3 pjh grad_cs    4096 Mar 28 15:51 chromium

When I invoke the chromedriver using the same python code as the OP:

driver = webdriver.Chrome('/path/to/chromedriver-2.9')

This leads to the exception message. In the chromedriver.log I found this message:

[1.043][INFO]: Launching chrome: /path/to/chromium ...

Unbelievable! The chromedriver is trying to use /path/to/chromium (which is not an executable file, but a directory containing source code) as the browser to execute! Apparently chromedriver tries to search the current directory for a browser to run before searching my PATH. So, one easy solution to this problem is to check the directory where the chromedriver is located for files/directories like chrome and chromium and move them to a different directory than the chromedriver.

A better solution is to explicitly tell selenium / chromedriver which browser to execute by using the chrome_options argument:

options = webdriver.ChromeOptions()
options.binary_location = '/opt/google/chrome/google-chrome'
service_log_path = "{}/chromedriver.log".format(outputdir)
service_args = ['--verbose']
driver = webdriver.Chrome('/path/to/chromedriver',
        chrome_options=options,
        service_args=service_args,
        service_log_path=service_log_path)

The chromedriver.log now shows:

[0.999][INFO]: Launching chrome: /opt/google/chrome/google-chrome ...

as expected.

Solution 3:

An alternative solution of using a virtual display is the headless mode.

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1420,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)

Solution 4:

If using Linux make sure you are not running as root. That what gave me the error.