Python 如何将 geckodriver 放入 PATH?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40388503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:28:37  来源:igfitidea点击:

How to put geckodriver into PATH?

pythonseleniumselenium-webdrivergeckodriver

提问by Matthew Garcia

I'm on OS Sierra and i'm running Python 3.5.2. I have selenium installed and i'm following a book called "Automate the Boring Tasks With Python"

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

My code is

我的代码是

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

I keep receiving the error

我一直收到错误

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. 

I have searched far and wide for solutions to my issue. Many people have the same issue.. but none of the solutions are working. I have geckodriver copied everywhere in my Python folders. I've tried using terminal and I have tried specifying the path within the code and it still gives me errors. I hope somebody can help me. I'm sorry if this is in the wrong format, I don't know what i'm doing.

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

回答by kiran.koduru

I faced this same problem and here's how I fixed it:

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

  1. Download the geckodriverfrom here
  2. Extract and unzip and move the geckodriverfile to /usr/local/bin/directory
  3. Run python program with selenium Firefoxwebdriver.
  1. geckodriver这里下载
  2. 提取并解压缩并将geckodriver文件移动到/usr/local/bin/目录
  3. 使用 selenium Firefoxwebdriver运行 python 程序。

回答by ddavison

This answer can be easily solved by a google search for "add program to path"

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

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

回答by TheoretiCAL

"I have geckodriver copied everywhere in my Python folders." Ensure the geckodriver executable is found in one of the paths when you run:

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

import sys
print sys.path

And the problem should be resolved.

问题应该得到解决。