You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac M1环境下Selenium网页爬取chromedriver路径错误求助

Mac M1设备上Selenium Chromedriver路径错误解决思路

问题描述

在Mac M1设备上使用Selenium爬取网页时,遇到chromedriver路径相关错误,代码及错误信息如下:

代码

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

chromeOptions = Options()
chromeOptions.headless = False

s = Service("usr/local/bin/chromedriver")
driver = webdriver.Chrome(service= s, options = chromeOptions )

错误信息

---------------------------------------------------------------------------
SeleniumManagerException                  Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in start(self)
     95                 try:
---> 96                     path = SeleniumManager().driver_location(browser)
     97                 except WebDriverException as new_err:

7 frames
SeleniumManagerException: Message: Selenium manager failed for: /usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/linux/selenium-manager --browser chrome. /usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/linux/selenium-manager: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found (required by /usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/linux/selenium-manager)
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/linux/selenium-manager: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/linux/selenium-manager)


During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in _start_process(self, path)
    210         except OSError as err:
    211             if err.errno == errno.ENOENT:
--> 212                 raise WebDriverException(
    213                     f"'{os.path.basename(self.path)}' executable needs to be in PATH. {self.start_error_message}"
    214                 )

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

解决方法

  • 修正路径拼写:代码中路径缺少开头斜杠,应改为/usr/local/bin/chromedriver,否则系统无法识别为绝对路径。
  • 匹配Chrome与chromedriver版本:
    1. 查看Chrome版本(设置→关于Chrome)。
    2. 下载对应版本的arm64架构chromedriver,解压后放到/usr/local/bin,或直接在代码中指定解压后的完整路径。
  • 用Homebrew安装:终端执行brew install chromedriver,安装完成后代码中无需手动指定路径,直接写Service()即可,Homebrew会自动处理架构和PATH配置。
  • 禁用Selenium Manager:若环境存在架构混淆,在代码开头添加:
    import os
    os.environ['SE_DONT_USE_SM'] = '1'
    
    确保手动指定的chromedriver是适配M1的arm64版本。
  • 检查Python架构:终端执行python3 -c "import platform; print(platform.machine())",确认输出为arm64。若为x86_64,重新安装适配M1的Python版本。

内容的提问来源于stack exchange,提问作者Ann09

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 16:31:19