Python Selenium ChromeDriver加载失败:WinError 193问题求助
问题描述
代码中使用的依赖库:
from arcgis.gis import GIS from arcgis.geometry import Point, Polyline, Polygon import datetime import os from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromeService from selenium.webdriver.common.keys import Keys from webdriver_manager.chrome import ChromeDriverManager import time from selenium.webdriver.support.select import Select from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from getpass import getpass
已执行pip install -r requirements.txt安装依赖,但运行代码时出现ChromeDriver加载错误,报错信息:
PS E:\code\esri\FissionStaking2> python .\marswaitforlogin.py enter in a ZULU time 00:00 -> 23:59 (15:10) for 3:10pm 14:30 Traceback (most recent call last): File "E:\code\esri\FissionStaking2\marswaitforlogin.py", line 34, in <module> driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install())) File "E:\code\esri\FissionStaking2\.venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__ super().__init__( File "E:\code\esri\FissionStaking2\.venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 55, in __init__ self.service.start() File "E:\code\esri\FissionStaking2\.venv\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start self._start_process(self._path) File "E:\code\esri\FissionStaking2\.venv\lib\site-packages\selenium\webdriver\common\service.py", line 208, in _start_process self.process = subprocess.Popen( File "E:\Program Files\Python310\lib\subprocess.py", line 971, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "E:\Program Files\Python310\lib\subprocess.py", line 1456, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, OSError: [WinError 193] %1 is not a valid Win32 application
请问缺少什么配置或操作导致该错误?
解决方案
- Chrome与ChromeDriver版本/架构不匹配:WinError193最常见原因是驱动和浏览器版本不对,或者32/64位架构不兼容。先查看Chrome版本(Chrome菜单→帮助→关于Google Chrome),要么手动下载对应版本的ChromeDriver替换自动下载的文件,要么在代码里指定版本安装:
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager(version="你的Chrome对应版本号").install())) - 自动下载的驱动损坏:WebDriverManager缓存的驱动可能因网络问题损坏,导致无法识别为有效Win32程序。删掉缓存文件夹(默认路径
C:\Users\<你的用户名>\.wdm\drivers\chromedriver)后重新运行代码,或者手动下载驱动后直接指定路径:driver = webdriver.Chrome(service=ChromeService(executable_path="你的ChromeDriver.exe完整路径")) - Python与驱动架构不匹配:如果你的Python是32位版本,却下载了64位ChromeDriver(反之亦然),会触发该错误。运行
python --version查看是否有32-bit标识,下载对应架构的驱动即可。 - Chrome安装异常:若Chrome浏览器本身安装损坏,或安装路径包含中文、特殊字符,也会导致驱动无法正常调用。尝试重装Chrome,确保安装路径无特殊字符。
内容的提问来源于stack exchange,提问作者robm
相关产品推荐
相关产品推荐

