【问题标题】:geckodriver executable needs to be in pathgeckodriver 可执行文件需要在路径中
【发布时间】:2016-10-14 17:33:38
【问题描述】:

我已阅读有关此主题的先前问题并尝试遵循建议,但我仍然遇到错误。在终端上,我跑了

export PATH=$PATH:/Users/Conger/Documents/geckodriver-0.8.0-OSX

我也试过

    export PATH=$PATH:/Users/Conger/Documents/geckodriver

当我运行以下 Python 代码时

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/Users/Conger/Documents/Firefox.app'

driver = webdriver.Firefox(capabilities=firefox_capabilities)

我仍然收到以下错误

Python - testwebscrap.py:8
Traceback (most recent call last):
  File "/Users/Conger/Documents/Python/Crash_Course/testwebscrap.py", line 11, in <module>
    driver = webdriver.Firefox(capabilities=firefox_capabilities)
  File "/Users/Conger/miniconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
    self.service.start()
  File "/Users/Conger/miniconda2/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x1006df6d0>> ignored
[Finished in 0.194s]

【问题讨论】:

  • 设法解决了这个问题!我没有创建新路径,而是将 geckodriver 文件添加到我的 bash_profile 中列出的路径中。立即工作!

标签: python


【解决方案1】:

您可以将硒降级

pip install selenium==2.53.6

这解决了我的问题

【讨论】:

  • 有比降级更好的选择吗?
  • 有效,但为什么?
  • ubuntu版本没有按照python包升级。所以我们可以降级 selenium 或者可以在路径中添加 gekodriver 并告诉路径
【解决方案2】:

在 Mac 上:

brew install geckodriver

Homebrew 是 Mac OS X 上最受欢迎的包管理器,您需要在您的 Mac 上安装 XCode,然后就可以从您的终端访问它。

如有需要,您可以关注this tutorial

【讨论】:

    【解决方案3】:

    首先我们知道gekodriver是Firefox的驱动引擎,我们知道 driver.Firefox()是用来打开火狐浏览器的,它会调用gekodriver引擎,所以我们需要给gekodirver一个可执行权限。 所以我们下载最新的gekodriver解压tar包,然后把gekodriver放到/usr/bin/ 好的,这就是我的答案,我已经测试过了。

    【讨论】:

    • 在 Ubuntu 18.04 LTS 上工作。非常简洁的答案。
    【解决方案4】:

    我刚刚从here 下载了最新版本的geckodriver(我有win7)并将该exe文件添加到python目录中(已经在PATH中)

    【讨论】:

    • 一旦我将 C:\Program Files (x86)\Python36-32\Lib\site-packages\selenium\webdriver\firefox 添加到我的系统路径并将 geckodriver.exe 文件放在该文件夹中运行良好(Windows 10.1)(我很确定我不应该放置确切的路径)
    【解决方案5】:

    导出路径仅在您输入命令的终端中有效。如果您尝试从不同的终端运行脚本,您将收到相同的错误。

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 2017-11-21
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 2018-03-25
      • 2018-07-11
      相关资源
      最近更新 更多