gpt4 book ai didi

macos - 网络驱动程序异常 : 'geckodriver' executable needs to be in PATH even though it is

转载 作者:行者123 更新时间:2023-12-04 03:00:07 24 4
gpt4 key购买 nike

尝试在 spyder 中使用 selenium 让 firefox 运行。我当前的代码是

from selenium import webdriver
import os
os.environ["PATH"] += ":/usr/local/bin/geckodriver"
browser = webdriver.Firefox()

我仍然得到这个错误:

runfile('/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py', 
wdir='/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder')
Traceback (most recent call last):

File "<ipython-input-1-3f3f96ccf515>", line 1, in <module>

runfile('/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py',
wdir='/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder')

File "/Applications/anaconda3/lib/python3.6/site-
packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "/Applications/anaconda3/lib/python3.6/site-
packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py",
line 12, in <module>
browser = webdriver.Firefox()

File "/Applications/anaconda3/lib/python3.6/site-
packages/selenium/webdriver/firefox/webdriver.py", line 152, in
__init__
self.service.start()

File "/Applications/anaconda3/lib/python3.6/site-
packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)

WebDriverException: 'geckodriver' executable needs to be in PATH.

即使 gekodriver 在该文件夹中。

proof that gekodriver is in the right place

我还尝试将路径导出到 ~./bash_profile,现在看起来像这样。

Last login: Fri Apr 20 10:57:16 on ttys000
dhcp-54-85:~ mherl$ nano ./bash_profile
dhcp-54-85:~ mherl$ nano .bash_profile
GNU nano 2.0.6 File: .bash_profile
Modified


# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# added by Anaconda3 5.1.0 installer
export PATH="/Applications/anaconda3/bin:$PATH"

#added by mherl to show path to gekodriver
export PATH=$PATH:/usr/local/bin/gekodriver

我还在 spyder 中设置了当前路径:

/usr/local/bin
/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder

其中gekodriver在

/usr/local/bin

我到处都看了,大多数人说如果它在/usr/local/bin 中它应该会自动运行,但即使我明确说明路径它似乎仍然找不到它。

如果重要的话,这是一台运行 High Sierra 的 mac。

最佳答案

这个错误信息...

WebDriverException: 'geckodriver' executable needs to be in PATH. 

...暗示未在预期的默认位置找到 GeckoDriver

解决方案

当您使用基于MAC 的系统时,您需要传递Key executable_path 以及Value 引用GeckoDriver绝对路径如下:

from selenium import webdriver

browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')

其他注意事项

确保以下内容:

  • GeckoDriver 出现在指定位置。
  • GeckoDriver 具有非根用户的可执行权限。
  • 以非根用户身份执行您的@Test。

关于macos - 网络驱动程序异常 : 'geckodriver' executable needs to be in PATH even though it is,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49947694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com