70

I'd like to construct my crawler using selenium on my server.

Thus I had installed/download required dependencies- such as chromedriver, chromium-browser etc on my Ubuntu17.10 server

However, when I run following code:

driver = webdriver.Chrome()

It returns following error:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-14-2cdab8938403> in <module>()
----> 1 driver = webdriver.Chrome()

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options)
     66             service_args=service_args,
     67             log_path=service_log_path)
---> 68         self.service.start()
     69 
     70         try:

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
     96         count = 0
     97         while True:
---> 98             self.assert_process_still_running()
     99             if self.is_connectable():
    100                 break

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
    109             raise WebDriverException(
    110                 'Service %s unexpectedly exited. Status code was: %s'
--> 111                 % (self.path, return_code)
    112             )
    113 

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

What does it mean that it's excited..?

I can't get what the original intention of that error code and where to start to fix it.

It looks very rare case.

Maybe relevant:

I had install ubuntu desktop 17.10 on my desktop but failed to get GUI boot. Thus I am just using terminal only, but it well works so far. I had installed ssh and remote controlling jupyter notebook from my mac to server desktop, and those errors comes from it. Hope this info is relevant to solve this error, otherwise will abort it.

1
  • I had a similar issue trying to do this on a Lambda via a ECR Image and it took me several days (including checking in this thread) to come to an easy answer here on stack overflow: stackoverflow.com/a/66594707/3460414 In particular, I implemented a fork of this repo that contains the all importand Dockerimage github.com/umihico/docker-selenium-lambda . I tried posting as an answer given it took me 5 days and a lot of wasted time scrolling around stackoverflow, but moderation does not allow links to similar answers. I genuinely hope it helps someone.
    – Ernesto
    Commented Jan 16 at 22:25

15 Answers 15

63

It seems chromedriver needs some extra libraries. This solved the issue for me:

apt-get install -y libglib2.0-0=2.50.3-2 \
    libnss3=2:3.26.2-1.1+deb9u1 \
    libgconf-2-4=3.2.6-4+b1 \
    libfontconfig1=2.11.0-6.7+b1

I was working on a similar setup using a docker container instead of a server/VM without X / GUI.

To figure out which dependencies are required I tried iteratively to run it from the command line like this: /opt/chromedriver/2.33/chromedriver --version over and over again.

Then at eache time I used commands like apt-cache search <STUFF> and apt-cache madison <STUFF> to figure out the exact version of the deb package needed by chromedriver 2.33 (in my case, but I guess something similar would work for any version of chromedriver).

Edit

As suggested in the comments, using the ldd command to print shared object dependencies may be another option. As of today my chromedriver version after a few years from the original answer is 83.0.4103.14 - the dependencies are different as well, but see below to get an idea of what could be missing:

$ /usr/local/bin/chromedriver --version
ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103@{#119})
$ ldd /usr/local/bin/chromedriver
        linux-vdso.so.1 (0x00007fffff7f0000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f414739d000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f414737a000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f414736f000)
        libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f4147246000)
        libnss3.so => /usr/lib/x86_64-linux-gnu/libnss3.so (0x00007f41470f7000)
        libnssutil3.so => /usr/lib/x86_64-linux-gnu/libnssutil3.so (0x00007f41470c4000)
        libnspr4.so => /usr/lib/x86_64-linux-gnu/libnspr4.so (0x00007f4147082000)
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f4146f45000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4146df6000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4146ddb000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4146be9000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4147e56000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f4146b76000)
        libplc4.so => /usr/lib/x86_64-linux-gnu/libplc4.so (0x00007f4146b6d000)
        libplds4.so => /usr/lib/x86_64-linux-gnu/libplds4.so (0x00007f4146b68000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f4146b3e000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f4146b38000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f4146b30000)
        libbsd.so.0 => /usr/lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f4146b14000)

From man ldd:

ldd prints the shared objects (shared libraries) required by each program or shared object specified on the command line.

...

In the usual case, ldd invokes the standard dynamic linker (see ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set to 1. This causes the dynamic linker to inspect the program's dynamic dependencies, and find (according to the rules described in ld.so(8)) and load the objects that satisfy those dependencies. For each dependency, ldd displays the location of the matching object and the (hexadecimal) address at which it is loaded.

4
  • 19
    I particularly appreciated your description of how you worked out dependencies (running with --version) and then how you used apt-cache search. That really helped me here, thanks!
    – Sam
    Commented Jul 17, 2018 at 11:36
  • 3
    FYI: I basically followed this solution, except that the version numbers are now outdated. Downloading with the base references like so worked for me: ``` libglib2.0-0 \ libnss3 \ libgconf-2-4 \ libfontconfig1 \ ``` I'm running in docker, so I also needed to add ``` curl -LO $CHROMIUM_DRIVER_LOCATION unzip chromedriver_linux64.zip ``` to my entrypoint and run my driver in headless mode.
    – aaron
    Commented May 14, 2020 at 17:08
  • 2
    I'm not sure if it is a better way, but another way to see which libraries are required is to use ldd. E.g. ldd /opt/chromedriver/x.xx/chromedriver, which will show a list of .so files. Search for the ones which are not found. This is at least a less iterative process
    – Codebling
    Commented Jan 4, 2022 at 18:18
  • For me, the error was actually in the chrome binary installed by Selenium Manager. First, I did the same thing with LDD but instead with the chrome binary: ldd ~/.cache/selenium/chrome/linux64/123.0.6312.86/chrome This produced a few missing libs: libXdamage.so.1 => not found, etc. I Just googled the names and installed the packages with APT and it runs now. Commented Apr 2 at 3:00
34

I encountered the same error when using selenium/chromedriver on my VPS. I installed chromium-browser and the problem was gone.

sudo apt-get install -y chromium-browser

Maybe it's not the chromium-browser is needed, but the packages were installed along with it. However, that was a quick fix.

3
  • 3
    "Package chromium-browser is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source"
    – JulienD
    Commented Oct 31, 2020 at 13:26
  • 5
    For anyone with the same problem as @JulienD, try sudo apt-get install -y chromium instead. More on stackoverflow.com/a/65586840/9216582
    – thlik
    Commented May 23, 2023 at 14:12
  • Yes for me sudo apt-get install -y chromium-browser doesn't work. Instead of I used : sudo apt-get update Then sudo apt-get install -y chromium chmod +x /path/to/chromedriver Then my browser was launched after I launched my tests Commented Mar 13 at 15:14
30

Run this command to troubleshoot: ./chromedriver (where your chrome driver binary is).

You might see an error like this:

./chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

To solve this error, simply run: sudo apt-get install libnss3.

Then check again and see if it works this time: ./chromedriver.

Some other packages might be missing as well. Here is an exhaustive list:

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

You probably don't need all of them but the ones you need are likely to be listed above.

4
  • 1
    In my case, this works: sudo apt-get install libnss3
    – B. Kanani
    Commented Mar 31, 2021 at 6:50
  • Good to know Thanks @B.Kanani! Commented Mar 31, 2021 at 8:16
  • I'm getting no package available. Commented Oct 3, 2022 at 22:06
  • @AbdulHaseeb it depends on which Linux distro you are using but usually a sudo apt-get update works. Commented Oct 4, 2022 at 3:42
8

I had a similar issue but it turned out that my problem was incorrectly set service_log_path which was pointing to a deleted folder.

webdriver.Chrome(executable_path='/path/to/chromedriver', service_log_path='/path/to/existing/folder')
1
  • I too faced the same problem with the log path and file does not exist. Once I created the log path and file, it succeed.
    – Karthik
    Commented Dec 23, 2021 at 10:58
5

While working with Selenium v3.11.0, ChromeDriver v2.36 and Chrome v64.x you have to download the latest ChromeDriver from the ChromeDriver - WebDriver for Chrome and place it within your system. Next while initializing the WebDriver and the WebBrowser you have to pass the argument executable_path along with the absolute path of the ChromeDriver as follows :

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
driver.get("http://www.python.org")
1
  • 1
    After brew cask install chromedriver you can initialize in the python script via driver = webdriver.Chrome("/usr/local/bin/chromedriver")
    – s2t2
    Commented Apr 6, 2019 at 19:42
4

I used such a script to install Chrome

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
apt update -y
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
apt install -y google-chrome-stable
3

@TPPZ 's answer need be updated

$ apt-get update -y
$ apt-get install -y libglib2.0-0 libnss3 libgconf-2-4 libfontconfig1
1

Solved by carefully removing existing chromedriver and updating it to a newer version:

  1. Delete all existing chromedriver files
  2. Download wget https://chromedriver.storage.googleapis.com/2.46/chromedriver_linux64.zip (replace 2.46 bit to the newer one if needed, see compatible versions here: http://chromedriver.chromium.org/downloads)
  3. Unzip, convert to executable by running chmod +x chromedriver
  4. Move it to mv -f chromedriver /usr/local/bin/chromedriver so it appears in PATH

This should solve an issue. I thought updating doesn't work because when I first tried it, I didn't remove the older version and I was still using it accidentally.

0
1

I was receiving the same selenium trace error:

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

My issue was due to using a different version of chromedriver (version 78) than browser (version 79) when trying to manually run the chromedriver I would see Segmentation fault (core dumped)

Once I updated my chromedriver to match the browser it was able to start successfully

Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 9515

Only local connections are allowed.

Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

1

I get this issue fixed by upgrading the Selenium version.

A side note for those who install Selenium by conda, the latest Selenium version on conda is pretty far behind the version on pip so please switch to pip installation.

0

I had this same issue, and the problem was due to chromedriver version.

Please ensure You are using latest Chrome Browser along with latest chromedriver.

0

Reverting to older versions might also be a solution...

I am using Ubuntu 18.10 and installed the latest Selenium (3.141.0) and ChromeDriver (75.0.3770.8), but also had the same permission problems, and status code 127 afterwards.

I tried installing Chromium and noticed that Ubuntu was using Version 73. So I reverted from the latest version of Chromedriver (75 at this time), back to Version 73 and that worked for me.

0

This error can occur if you're running a IDE in the cloud. GITPOD etc. Try creating a local repo and VSCode (or your chosen IDE) and selenium should work fine.

0

Created a Gitpod Repository for it.

  1. Open the repository in Gitpod by visiting: Open in Gitpod

  2. Let the scraping begin by running the following command in the Gitpod terminal:

    python main.py
    
0

This command fixed it for me. Just install Chrome driver.

sudo apt install chromium-chromedriver

Not the answer you're looking for? Browse other questions tagged or ask your own question.