FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'geckodriver': 'geckodriver' with GeckoDriver and Python in MAC OS [英] FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver' with GeckoDriver and Python in MAC OS

查看:49
本文介绍了FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'geckodriver': 'geckodriver' with GeckoDriver and Python in MAC OS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个测试脚本来使用 python 在 Eclipse 中打开一个 url 并得到以下错误:

I have created a test script to open a url in Eclipse using python and got the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 769, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1516, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'

在处理上述异常的过程中,又发生了一个异常:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/Eclipse.app/Contents/MacOS/C:EclipseWorkspacescsse120/PythonSeleniumProject/src/PythonSeleniumModule.py", line 13, in <module>
    driver = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

我在堆栈溢出中阅读了有关相关主题的内容,但没有一个能回答/解决我的问题.

I have read in stack overflow about related topics but none of them answers/solves my problem.

请指教.谢谢.

推荐答案

此错误信息...

FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'
.
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

...表示您的程序无法在上述目录中找到 GeckoDriver.

...implies that your program was unable to locate the GeckoDriver within the mentioned directory.

根据您使用的代码试验:

As per your code trials you have used:

driver = webdriver.Firefox()

由于您没有明确提到 GeckoDriver绝对路径,您的程序会在 路径中搜索 GeckoDriver 在您的基础操作系统 PATH 变量中提及并且无法定位.

As you havn't mentioned the absolute path of the GeckoDriver explicitly, your program searches for the GeckoDriver within the paths mentioned within your underlying Operating System PATH variable and unable to locate.

  • 当您使用 Mac OS X 时,请从 mozilla/geckodriver,将其存储在系统中的任何位置.
  • 在您的程序中,通过参数 executable_path 覆盖 操作系统 PATH 变量中提到的 paths如下:

  • As you are on Mac OS X download the latest geckodriver-v0.23.0-macos.tar.gz from mozilla/geckodriver, store it anywhere within your system.
  • In your program override the paths mentioned in your Operating System PATH variable through the argument executable_path as follows:

from selenium import webdriver

driver = webdriver.Firefox(executable_path='/path/to/geckodriver')
print("Firefox Browser Invoked")
driver.get('http://google.com/')
driver.quit()

这篇关于FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'geckodriver': 'geckodriver' with GeckoDriver and Python in MAC OS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆