ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.82k stars 1.15k forks source link

`zsh: no such file or directory .../undetected-chromedriver` #1405

Open thanhnguyen2187 opened 1 year ago

thanhnguyen2187 commented 1 year ago

I encountered this confusing error and wanted to note the cause and solution here.


Executing the code gave:

Traceback (most recent call last):
  File "/home/thanh/Sources/thanhnguyen2187/dune-query-repl/venv/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 194, in _start_process
    self.process = subprocess.Popen(
  File "/nix/store/xlr8ivnb7qgjqh279zcac6fj8h2gvah0-python3-3.10.9/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/xlr8ivnb7qgjqh279zcac6fj8h2gvah0-python3-3.10.9/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/thanh/.local/share/undetected_chromedriver/undetected_chromedriver'

Try executing the binary gave:

zsh: no such file or directory: /home/thanh/.local/share/undetected_chromedriver/undetected_chromedriver

I was using zsh on NixOS and encountered this after pip install undetected-chromedriver. The problem was with the way NixOS handle paths, which makes some required C libraries missing:

ldd /home/thanh/.local/share/undetected_chromedriver/undetected_chromedriver
# linux-vdso.so.1 (0x00007ffdfbd63000)
# libdl.so.2 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libdl.so.2 (0x00007f23000fd000)
# libpthread.so.0 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libpthread.so.0 (0x00007f23000f8000)
# libglib-2.0.so.0 => not found
# libnss3.so => not found
# libnssutil3.so => not found
# libnspr4.so => not found
# libm.so.6 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libm.so.6 (0x00007f2300016000)
# libxcb.so.1 => not found
# libgcc_s.so.1 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libgcc_s.so.1 (0x00007f22ffffc000)
# libc.so.6 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib/libc.so.6 (0x00007f22ffdf3000)
# /lib64/ld-linux-x86-64.so.2 => /nix/store/2j8jqmnd9l7plihhf713yf291c9vyqjm-glibc-2.35-224/lib64/ld-linux-x86-64.so.2 (0x00007f2300f7d000)

Manually adding the missing libraries and making them visible should help.

thanhnguyen2187 commented 1 year ago

One horrible way to work around this is to use nix-alien to create a new shell with every libraries included:

nix-alien \
    -l libdl.so.2 \
    -l libpthread.so.0 \
    -l libglib-2.0.so.0 \
    -l libnss3.so \
    -l libnssutil3.so \
    -l libnspr4.so \
    -l libm.so.6 \
    -l libxcb.so.1 \
    -l libgcc_s.so.1 \
    -l libc.so.6 \
    -l ld-linux-x86-64.so.2 \
    -l libpcre2-8.so.0 \
    -l libplds4.so \
    -l libplc4.so \
    -l librt.so.1 \
    -l libXau.so.6 \
    -l libXdmcp.so.6 \
    /nix/store/91jlw0ppx0zbzwz01q6wdjqyakrz6kmf-system-path/bin/bash \
;

Replace .../bin/bash with your shell, and then activate virtual environment, and then start working as usual.

thanhnguyen2187 commented 1 year ago

In case you don't need/can't afford "hard automation" (auto login/captcha bypassing) and therefore don't truly need undetected-chromedriver, you can try opening Chrome's WebDriver port like google-chrome-stable --remote-debugging-port=9222, do the login/captcha entering, and then attach your "normal" Selenium code to do your automation:

options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(options=options)