2

Trying to run selenium python on a Docker Apline Linux and getting the "Message: 'chromedriver' executable needs to be in PATH" error because it thinks the file doesn't exist. But tried everything I can fine in other answers, but it still won't launch.

Here's what I tried so far:

  • Added it to folder to PATH and PYTHONPATH.
  • Tried specifying path to chromedriver when I get the driver
  • Tried specifying path to chromium when I get the driver
  • Made sure chromium-browser launches with similar flags
  • chmod +x on chromedriver
  • chmod 777 on chromedriver

See error. in a docker un of image

Update: Adding these packages in Docker file.

RUN apk --update --no-cache add\
  alpine-sdk\
  autoconf\
  automake\
  bash\
  binutils-gold\
  build-base\
  curl\
  dumb-init\
  g++\
  gcc\
  gcompat\
  git\
  gnupg\
  gzip\
  jpeg\
  jpeg-dev\
  libc6-compat\
  libffi\
  libffi-dev\
  libpng\
  libpng-dev\
  libstdc++\
  libtool\
  linux-headers\
  make\
  mysql\
  mysql-client\
  mysql-dev\
  mesa-gles\
  nasm\
  nodejs\
  nss\
  openjdk8-jre\
  openssh-client\
  paxctl\
  python3\
  python3-dev\
  sudo\
  tar\
  unzip\
  wget\
  chromium

And the shell script I'm getting Chromedriver with

#!/bin/bash

LATEST_CHROMEDRIVER=$(curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
curl -L https://chromedriver.storage.googleapis.com/$LATEST_CHROMEDRIVER/chromedriver_linux64.zip >> chromedriver.zip
mv -f chromedriver.zip /usr/local/bin/chromedriver.zip
unzip /usr/local/bin/chromedriver.zip -d /usr/local/bin
chmod a+x /usr/local/bin/chromedriver
sudo ln -s /usr/local/bin/chromedriver /usr/bin/chromedriver
rm /usr/local/bin/chromedriver.zip
10
  • Try removing /usr/local/bin/chromedriver from your PATH. You want directories, not files. Also, even though you have 777 on the file, I would double check you can open() that file from Python. Commented Mar 11, 2019 at 22:28
  • Good call on path, now set to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin but does not fix the problem. fh = open(chromedriver_path, "r") can read the file Commented Mar 11, 2019 at 22:57
  • When you set your chromedriver_path, why do you start with the current working directory os.getcwd(), ...? I'm not sure what that returns, but I don't know why you can't just set chromedriver_path = /usr/local/bin/chromedriver Commented Mar 11, 2019 at 23:15
  • I actually started with that. Was kinda trying to combine every answer to similar questions so it doesn't get marked a dupe. But I switched back and it doesn't fix it. Commented Mar 11, 2019 at 23:19
  • Now that you fixed PATH, does which chromedriver return the right file? What happens if you start webdriver.Chrome without specifying an executable path? Commented Mar 12, 2019 at 15:10

1 Answer 1

3

The output from ldd suggests that chromedriver is built against glibc (GNU standard C library), which isn't compatible to vanilla Alpine, using musl libc.

To fix this, try installing the Alpine compatible version of chromedriver, available in Alpine repositories, using apk add chromium-chromedriver:

https://pkgs.alpinelinux.org/package/v3.9/community/x86_64/chromium-chromedriver

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your help. I actually went to apk install and that does work but before i accept the answer. Was wondering if there's a way to install the correct package of glibc on alpine and build against that. Trying something like stackoverflow.com/a/37835009/3838981. But still getting an error. Is there a way to tell which glibc the current chromedriver is built against? I've also added the shell script that I'm getting chromedriver with to question just in case. Would prefer to accept something like apk add is easier but still answer original questions how.
@Cynic sure - glad that worked. For installing glibc, follow the steps in this Dockerfile, for example: github.com/shaharv/docker/blob/master/alpine/glibc/Dockerfile. It is a custom built glibc linked against musl, by Sasha Gerrand (github.com/sgerrand/alpine-pkg-glibc). The steps are basically downloading the glibc apk file, installing it, and running ldconfig for updating the dynamic linker.
For getting the minimal glibc version required by chromedriver, you'll need to dump object symbols and look for GLIBC strings, something like: objdump -T chromedriver | grep GLIBC. See here: agardner.me/golang/cgo/c/dependencies/glibc/kernel/linux/2015/…
Few other notes: 1. Based on the download link it seems that the zip is Linux/mac, which mostly means its linked against glibc - which is the defacto standard libc used in most Linuxes - and indeed not musl libc, used by Alpine. 2. Regarding to libc6-compat and gcompat: installing them won't do (at least not for complex applications as chromedriver), since they are sort of "adapters" on top of musl, that merely provide glibc interfaces, but not the actual glibc with its issues and quirks.
Aw, sorry I edited down the bash script for simplicity and edited out the wrong link. Fixed in question. Will try the rest in a bit when I get time.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.