首页 文章

如何将geckodriver放入PATH? [重复]

提问于
浏览
7

这个问题在这里已有答案:

我在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 . 我尝试使用终端,我已经尝试在代码中指定路径,它仍然给我错误 . 我希望有人可以帮助我 . 如果格式错误,我很抱歉,我不知道我在做什么 .

3 回答

  • 0

    我遇到了同样的问题,这就是我修复它的方法:

    • here下载 geckodriver

    • 解压缩并解压缩并将 geckodriver 文件移动到 /usr/local/bin/ 目录

    • 用selenium Firefox webdriver运行python程序 .

  • 1

    这个答案可以通过谷歌搜索“添加程序到路径”轻松解决

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

    “我在我的Python文件夹中随处可见geckodriver . ”运行时,确保在其中一个路径中找到geckodriver可执行文件:

    import sys
    print sys.path
    

    问题应该得到解决 .

相关问题