【问题标题】:How to put geckodriver into PATH? [duplicate]如何将 geckodriver 放入 PATH? [复制]
【发布时间】:2017-03-16 06:29:33
【问题描述】:

我在 OS Sierra 上运行 Python 3.5.2。我已经安装了 selenium,我正在关注一本名为“使用 Python 自动化无聊的任务”的书

我的代码是

from selenium import webdriver
>>> browser = webdriver.Firefox()

我不断收到错误消息

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
browser = webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/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. 

我已经广泛搜索了我的问题的解决方案。很多人都有同样的问题..但没有一个解决方案有效。我在我的 Python 文件夹中到处都复制了 geckodriver。我试过使用终端,也试过在代码中指定路径,但它仍然给我错误。我希望有人能帮助我。很抱歉,如果格式错误,我不知道我在做什么。

【问题讨论】:

  • 你使用的是什么版本的Firefox
  • 我使用的是 Firefox 49.0.2
  • 您只需要在PATH变量中设置可执行geckodriver所在的目录,而不是在PATH中设置可执行geckodriver本身。谢谢
  • @SaurabhGaur 我看到了完全相同的问题,这与我遇到的问题相同。然而,没有一个答案对我有用。

标签: python selenium selenium-webdriver geckodriver


【解决方案1】:

我遇到了同样的问题,我是这样解决的:

  1. here下载geckodriver
  2. 解压并解压geckodriver文件到/usr/local/bin/目录
  3. 使用 selenium Firefox webdriver 运行 python 程序。

【讨论】:

  • 我已经这样做了,但我仍然遇到同样的问题。
  • geckodriver 文件的文件权限是什么?
  • 设置为所有人读写。我还设置了安全设置以打开从任何地方下载的应用程序。
  • @MatthewGarcia 很酷。它必须是可执行文件,否则它将永远不会运行。你能运行chmod ugo+x geckodriver吗?
  • @MatthewGarcia 还是同样的错误?
【解决方案2】:

您需要将二进制文件添加到您的$PATH。你可以这样做:

export PATH=$PATH:/path/to/geckodriver

【讨论】:

    【解决方案3】:

    “我的 Python 文件夹中到处都复制了 geckodriver。” 确保运行时在其中一个路径中找到 geckodriver 可执行文件:

    import sys
    print sys.path
    

    问题应该解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 2020-12-24
      • 1970-01-01
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      相关资源
      最近更新 更多