Python 找不到Chromedriver路径?-硒马科斯
我已经在MacOS上下载了Selenium和Chromedriver,但似乎无法在空闲的Python Shell上执行:Python 找不到Chromedriver路径?-硒马科斯,python,macos,selenium,selenium-chromedriver,Python,Macos,Selenium,Selenium Chromedriver,我已经在MacOS上下载了Selenium和Chromedriver,但似乎无法在空闲的Python Shell上执行: driver = webdriver.Chrome() 错误消息返回: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/servic
driver = webdriver.Chrome()
错误消息返回:
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 756, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1499, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
driver = webdriver.Chrome()
File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/selenium/webdriver/chrome/webdriver.py", line 68, 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: 'chromedriver'
executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
回溯(最近一次呼叫最后一次):
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/selenium/webdriver/common/service.py”,第76行,开头
标准偏差=管道)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py”,第756行,在__
恢复信号,启动新会话)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py”,第1499行,在执行子进程中
引发子项异常类型(错误号、错误消息、错误文件名)
FileNotFoundError:[Errno 2]没有这样的文件或目录:“chromedriver”:“chromedriver”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
driver=webdriver.Chrome()
文件
“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/selenium/webdriver/chrome/webdriver.py”,第68行,在__
self.service.start()
文件
“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/selenium/webdriver/common/service.py”,第83行,开始
os.path.basename(self.path)、self.start\u错误消息)
selenium.common.exceptions.WebDriverException:消息:“chromedriver”
可执行文件需要在路径中。请看
https://sites.google.com/a/chromium.org/chromedriver/home
我试图将Chromedriver设置为正确的路径,方法是将其放置在usr/local/bin中,并将其放置在所附图像的selenium文件夹中。然而,我不确定它是否在正确的位置,因为同样的错误仍然出现
我该如何解决这个问题
非常感谢你
如您所知,主要错误是chromedriver可执行文件不在路径中。在Python脚本中执行以下操作以指定路径:
import sys
path = '/path/to/your/chromedriver/executable'
sys.path.append(path)
# then continue your script
据我所知,chromedriver可执行文件不需要位于
bin
目录中,就可以工作;你可以把它放在任何地方,只要你使用上面的代码指定它在哪里,你的程序就可以找到它。我应该如何找到我的Chromedriver?有没有办法让我在候机楼打电话告诉我很抱歉,我是编程新手。你说你把Chromedriver放在了usr/local/bin/
中。在该文件夹中找到它并执行。这是我见过的Mac用户最简单的方式(我不是Mac用户)