MacOS下chromedriver_autoinstaller报错求助:未找到Chrome可执行文件
解决MacOS下chromedriver_autoinstaller报错问题
问题分析
从报错信息看,模块调用了get_linux_executable_path()函数,说明它误将MacOS识别为Linux系统,导致找不到Chrome可执行文件的正确路径。以下是具体解决步骤:
确认Chrome安装路径
MacOS上Chrome默认安装路径为/Applications/Google Chrome.app/Contents/MacOS/Google Chrome,先手动检查该路径是否存在。手动指定Chrome路径
在install()方法中传入Chrome的实际路径,强制模块识别正确位置:from selenium import webdriver import chromedriver_autoinstaller chromedriver_autoinstaller.install(chrome_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")添加Chrome路径到环境变量
打开终端执行以下命令,将Chrome路径加入PATH(根据你的shell类型选择对应配置文件):# 若使用zsh echo 'export PATH="/Applications/Google Chrome.app/Contents/MacOS:$PATH"' >> ~/.zshrc source ~/.zshrc # 若使用bash echo 'export PATH="/Applications/Google Chrome.app/Contents/MacOS:$PATH"' >> ~/.bash_profile source ~/.bash_profile完成后重启Python环境重试。
升级模块版本
旧版本可能存在系统识别bug,执行升级命令:pip install --upgrade chromedriver_autoinstaller替换为webdriver-manager(备选方案)
如果上述方法无效,建议换用对多系统支持更稳定的webdriver-manager:from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
内容的提问来源于stack exchange,提问作者Simon Kianzad
相关产品推荐
相关产品推荐

