Solving WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127 in Python

WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127 is an error which occurs when your Selenium installation is missing certain libraries.

In this article I am going to explain why the error is happening and how to install Selenium properly without getting the error again. Also we are going to check out other solutions that may work for your particular case.

Describing WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127 in Python

The error usually occurs when your machine does not have the libraries required to run chromedriver.

Before we get into the fix, you might be wondering how we can replicate the error.

The error can happen with any script using webdriver with Python, just the following line of code can cause the error.

                                                                       #
driver = webdriver.Chrome()
                                                                       #

Bellow is an example of the error you can get.

                                                                       #
WebDriverException Traceback (most recent call last)
<ipython-input-14-2cdab8938403> in <module>()
----> 1 driver = webdriver.Chrome()
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127
                                                                       #

Bellow we will describe how the error can be solved. With multiple possible solution.

Solution 1 : install the chromium-browser

One of the tricks one can try to solve this error quickly is to install the chromium-browser

This may work if one of the missing libraries is automatically installed with the chromium-browser

You can install the chromium-browser using the code bellow

                                                                       #
sudo apt-get install -y chromium-browser
                                                                       #

Solution 2 : install all the missing libraries in Selenium

The second solution is a bit harder and may take some time, the fix is to manually install the missing libraries.

To speed the process up you can periodically install libraries one by one while trying to run your faulty code until the error is gone.

This way you wont have to install all the libraries.

This is a list of the libraries that could be missing.

                                                                       #
wget libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libappindicator1 libnss3 lsb-release xdg-utils ca-certificates fonts-liberation libxcursor1 libxdamage1 libxext6 libpango-1.0-0 libpangocairo-1.0-0 libfontconfig1 libgcc1 libgconf-2-4 gconf-service libasound2 libatk1.0-0
                                                                       #

You can install a library using this code for example.

                                                                       #
sudo apt-get install libxi6
                                                                       #

Solution 3 : use some commands to install chrome the right way

The last solution is to run a list of commands in order to install chrome the right way, so follow the instructions bellow.

                                                                       #
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
                                                                       #

This will get rid of most of the errors during the installation.

                                                                       #
apt update -y
                                                                       #

Now, Let us install a list of essential libraries using the command bellow

                                                                       #
apt install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils
                                                                       #

Finally, let us install chrome

                                                                       #
apt install -y google-chrome-stable
                                                                       #

Summing-up

This article is over guys, You can support us by donating to our Kofi account, you can find a red button at the top of this page.

Good luck with your Python journey, keep coding, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/