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

初始化Chrome Driver时Python脚本报错求助(Windows 8.1环境)

问题排查:Selenium启动Chrome失败报错

环境信息

  • 系统:Windows 8.1
  • Python版本:3.12.0
  • PowerShell版本:7.3.9
  • 开发工具:VSCode(使用内置终端)

代码

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import selenium


chrome_driver_path = "D:\Downloads\chromedriver.exe"
options = Options()
options.add_argument("start-maximized")
options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"
chrome_service = webdriver.chrome.service.Service(chrome_driver_path)
driver = webdriver.Chrome(service=chrome_service, options=options)
driver.get('https://studio.youtube.com/channel/UC57gBc9mbUVAXRdkOfPKaYw/videos/upload')

相关版本

  • Chrome浏览器:109.0.5414.169
  • Chrome WebDriver:109.0.5414.74
  • Selenium:4.15.2

报错内容

Traceback (most recent call last):
  File "d:\Downloads\upload.py", line 54, in <module>
    driver = webdriver.Chrome(service=chrome_service, options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Sarker Ayon\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\Sarker Ayon\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 61, in __init__
    super().__init__(command_executor=executor, options=options)
  File "C:\Users\Sarker Ayon\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 209, in __init__
    self.start_session(capabilities)
  File "C:\Users\Sarker Ayon\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Sarker Ayon\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 348, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Sarker Ayon\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process.
Stacktrace:
Backtrace:
        (No symbol) [0x00D06643]
        (No symbol) [0x00C9BE21]
        (No symbol) [0x00B9DA9D]
        (No symbol) [0x00BBD95D]
        (No symbol) [0x00BBA899]
        (No symbol) [0x00BF6917]
        (No symbol) [0x00BF655C]
        (No symbol) [0x00BEFB76]
        (No symbol) [0x00BC49C1]
        (No symbol) [0x00BC5E5D]
        GetHandleVerifier [0x00F7A142+2497106]
        GetHandleVerifier [0x00FA85D3+2686691]
        GetHandleVerifier [0x00FABB9C+2700460]
        GetHandleVerifier [0x00DB3B10+635936]
        (No symbol) [0x00CA4A1F]
        (No symbol) [0x00CAA418]
        (No symbol) [0x00CAA505]
        (No symbol) [0x00CB508B]
        BaseThreadInitThunk [0x773B6A24+36]
        RtlInitializeExceptionChain [0x776FA9FF+143]
        RtlInitializeExceptionChain [0x776FA9CA+90]

解决方法

1. 修复路径转义问题

Windows路径中的\是转义字符,直接编写会被解析为特殊字符,导致路径识别错误。将路径修改为以下两种格式之一:

  • 使用双反斜杠:
    chrome_driver_path = "D:\\Downloads\\chromedriver.exe"
    options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
    
  • 使用原始字符串(路径前加r):
    chrome_driver_path = r"D:\Downloads\chromedriver.exe"
    options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
    

2. 清理残留进程

打开任务管理器,结束所有chrome.exe和chromedriver.exe进程,再重新运行代码,避免进程占用导致无法启动新实例。

3. 确保版本完全匹配

当前Chrome版本为109.0.5414.169,WebDriver版本为109.0.5414.74,主版本一致但小版本存在差异。建议下载与Chrome完全匹配的WebDriver版本,消除兼容性隐患。

4. 提升运行权限

右键VSCode图标,选择「以管理员身份运行」,再执行代码,避免因权限不足无法创建Chrome进程。

5. 简化启动参数(可选)

如果上述方法无效,先移除options.binary_location配置,让Selenium自动查找Chrome路径,测试基础启动是否正常:

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

chrome_driver_path = r"D:\Downloads\chromedriver.exe"
options = Options()
options.add_argument("start-maximized")
chrome_service = Service(chrome_driver_path)
driver = webdriver.Chrome(service=chrome_service, options=options)
driver.get('https://studio.youtube.com/channel/UC57gBc9mbUVAXRdkOfPKaYw/videos/upload')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 17:29:57