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

Selenium报错OSError: [WinError 193] 非有效Win32应用求助

Selenium脚本突发执行失败的排查与解决

问题情况

之前运行完全正常的Selenium脚本突然无法执行,未对脚本或Python环境做任何修改,Python及相关DLL均为64位,报错提示OSError: [WinError 193] %1 is not a valid Win32 application。

运行代码

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

options = webdriver.ChromeOptions()
options.add_argument('log-level=3')
driver = webdriver.Chrome(options=options, service=Service(ChromeDriverManager().install()))

错误信息

"C:\Users\19DelgadoJos\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\19DelgadoJos\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 50, in __init__
    self.service.start()
  File "C:\Users\19DelgadoJos\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
    self._start_process(self._path)
  File "C:\Users\19DelgadoJos\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\service.py", line 208, in _start_process
    self.process = subprocess.Popen(
                   ^^^^^^^^^^^^^^^^^
  File "C:\Users\19DelgadoJos\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\19DelgadoJos\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1538, in _execute_child      
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 193] %1 is not a valid Win32 application   
PS C:\Users\19DelgadoJos\Desktop\Code\videomaker> 

排查解决步骤

  • 清理ChromeDriver缓存:webdriver-manager可能下载了损坏/位数不匹配的驱动。找到缓存目录(通常为C:\Users\<你的用户名>\.wdm\drivers\chromedriver),删除所有文件后重新运行脚本,让工具重新下载对应版本驱动。
  • 校验Chrome版本匹配:确保Chrome浏览器与ChromeDriver版本完全同步。若浏览器自动更新,驱动可能未同步,手动下载对应版本的ChromeDriver替换缓存文件。
  • 检查Python环境变量:确认系统PATH中仅保留64位Python路径,无32位Python干扰。命令行运行python --version,查看是否标注64-bit。
  • 修复Python安装:无需完全卸载重装,打开Python安装程序选择「Modify」,点击「Repair」修复可能损坏的系统文件或关联。
  • 排查杀毒软件拦截:部分杀毒软件会误删/隔离ChromeDriver可执行文件,检查隔离区并将ChromeDriver加入信任列表。

内容的提问来源于stack exchange,提问作者josh.delgado

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 19:05:12