Python OSError: [Errno 8] Exec 格式错误硒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38833589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:28:16  来源:igfitidea点击:

OSError: [Errno 8] Exec format error selenium

pythonselenium

提问by Satish Gupta

Trying to learn how to use selenium, I managed to overcome first error which involved chrome driver not being in the path name but it has thrown up another error.

尝试学习如何使用 selenium,我设法克服了第一个错误,该错误涉及 chrome 驱动程序不在路径名中,但它引发了另一个错误。

  from selenium import webdriver
    from selenium.webdriver.common.keys import Keys


    driver = webdriver.Chrome('/Users/williamneal/Scratch/Titanic/chromedriver')
    driver.get("http://www.bbc.com")

The error: Traceback (most recent call last):

错误:回溯(最近一次通话):

  File "<ipython-input-1-84256e62b8db>", line 5, in <module>
    driver = webdriver.Chrome('/Users/williamneal/Scratch/Titanic/chromedriver')

  File "/Users/williamneal/anaconda/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()

  File "/Users/williamneal/anaconda/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)

  File "/Users/williamneal/anaconda/lib/python3.5/subprocess.py", line 950, in __init__
    restore_signals, start_new_session)

  File "/Users/williamneal/anaconda/lib/python3.5/subprocess.py", line 1544, in _execute_child
    raise child_exception_type(errno_num, err_msg)

OSError: [Errno 8] Exec format error

There is a potential solution here, which involves installing Chrome Drivers via Home Brew but that option is not available to me.

有一个潜在的解决方案在这里,它涉及到通过家酿安装Chrome驱动程序但选项不可用我。

Any ideas?

有任何想法吗?

回答by Satish Gupta

Looks like this is complaining about the format of chromedriver binary. It might be because of platform and chromedriver format mismatch. For example windows requires chromedriver.exe while there are different formats for linux and mac.

看起来这是在抱怨 chromedriver 二进制文件的格式。这可能是因为平台和 chromedriver 格式不匹配。例如 windows 需要 chromedriver.exe,而 linux 和 mac 有不同的格式。

If you don't want to install through package manager, just download chromedriver from https://sites.google.com/a/chromium.org/chromedriver/downloads

如果您不想通过包管理器安装,只需从https://sites.google.com/a/chromium.org/chromedriver/downloads下载 chromedriver

Note : Choose file as per your os

注意:根据您的操作系统选择文件

Then place it anywhere on the os and pass that path as an argument. You can also set webdriver.chrome.driver environment variable if you don't want to pass the location every time.

然后将它放在操作系统上的任何位置并将该路径作为参数传递。如果不想每次都传递位置,也可以设置 webdriver.chrome.driver 环境变量。

回答by janDro

FYI you could also encounter this issue if you did not unzip the chromedriver before adding it to your PATH.

仅供参考,如果您在将 chromedriver 添加到 PATH 之前没有解压缩它,您也可能会遇到此问题。