Search code examples
python-3.xseleniumwebdriverselenium-chromedriverraspberry-pi3

OSError: [Errno 8] Exec format error using ChromeDriver with Selenium and Linux on Raspberry Pi


Im trying to access and interact with a website using selenium and the chrome driver. I downloaded the chrome driver from here, specifically I downloaded version 2.45 and the linux64 version because I'm on raspberry pi. I also installed geckodriver the arm version for linux. I unzipped both of these files and moved them to my /usr/bin folder because that is where my python 3 path is. Here is my code:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.google.com")

I run this code and the error message I get is

Traceback (most recent call last):
  File "/home/pi/test with selenium.py", line 2, in <module>
    driver = webdriver.Chrome()
  File "/home/pi/.local/lib/python3.5/site- 
packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.5/site- 
packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error

I checked to make sure chromedriver is an executable file and it is, I know this from looking under properties and permissions and it says anyone can execute the file. I tried installing homebrew (I'm not sure if I did it right) and running brew install chromedriver, still didn't work. Another solution I read online thought I had the wrong chromedriver file for my operation system, but I am pretty sure I do. This is my first time using selenium, so hopefully, I'm not doing it completely wrong. Any help is appreciated!


Solution

  • I finally managed to get chromedriver to work on raspberry pi! The first thing I was doing wrong was using the latest version of chromedriver (version 2.45) which only works for Chrome versions 70-72. Currently (December 2018) the highest version of Chromium (open source Chrome) available on raspberry pi is 65 (source). So that meant that chromedriver versions 2.36 - 2.38 SHOULD work, yet they didn't. Why they still gave me that OS Error, I still don't understand. However I found a useful reddit post (yes, reddit) which I will link here. Basically, instead of downloading chromedriver from their offical website I needed to download it from here. This website has chromedriver for arm, rather than just linux 64 bit. So I clicked on chromedriver 65 in armhf (updates), and downloaded the .deb file seen on the right side of the page. Then I opened it by double clicking and my raspberry pi unzipped the .deb file and gave me a file named chromedriver located in /usr/lib/chromium-browser. I ran sudo mv /usr/lib/chromium-browser/chromedriver /usr/bin in terminal to move the chromedriver file to my python directory. Now this piece of selenium code worked perfectly in python and on raspberry pi:

    from selenium import webdriver driver = webdriver.Chrome()

    Again, I wouldn't have solved this without the helpful reddit post I will link again here. All of the steps I described above are described in the reddit post, I'm just trying to get the word out!