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

启动4个及以上Selenium Chrome Driver时触发Permission Error

启动多个Chrome Driver实例时出现权限拒绝错误的解决方案

启动1、2或3个Chrome Driver实例时一切正常,但尝试启动第4个及更多实例时,会出现权限拒绝错误,报错信息如下:

Traceback (most recent call last):
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\file_manager.py", line 65, in __extract_zip
    archive.extractall(to_directory)
  File "C:\Users\jan\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1642, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "C:\Users\jan\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1696, in _extract_member
    open(targetpath, "wb") as target:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\jan\\.wdm\\drivers\\chromedriver\\win64\\115.0.5790.171\\chromedriver-win32\\chromedriver.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\jan\PycharmProjects\email_creating\main.py", line 110, in <module>
    driver =webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\chrome.py", line 40, in install
    driver_path = self._get_driver_binary_path(self.driver)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\manager.py", line 41, in _get_driver_binary_path
    binary_path = self._cache_manager.save_file_to_cache(driver, file)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\driver_cache.py", line 54, in save_file_to_cache
    files = self.unpack_archive(archive, path)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\driver_cache.py", line 49, in unpack_archive
    return self._file_manager.unpack_archive(archive, path)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\file_manager.py", line 57, in unpack_archive
    return self.__extract_zip(archive_file, target_dir)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\file_manager.py", line 81, in __extract_zip
    os.replace(source, destination)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\jan\\.wdm\\drivers\\chromedriver\\win64\\115.0.5790.171\\chromedriver-win32\\chromedriver.exe' -> 'C:\\Users\\jan\\.wdm\\drivers\\chromedriver\\win64\\115.0.5790.171\\chromedriver.exe'

运行的代码如下:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from webdriver_manager.chrome import ChromeDriverManager
import time

options = Options()
options.add_experimental_option("detach", True)
options.add_argument("--disable-logging")
options.add_argument("--disable-login-animations")
options.add_argument("--disable-notifications")
options.add_argument("--incognito")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--disable-blink-features=AutomationControlled")

if __name__ == "__main__":
    amount = 4
    i=0
    drivers = []
    for _ in range(amount):
        driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
        drivers.append(driver)
        time.sleep(1)

解决方案

  • 提前获取ChromeDriver路径,避免重复安装/解压
    原代码每次循环都调用ChromeDriverManager().install(),多个进程会同时读写同一个chromedriver.exe文件引发权限冲突。修改为循环外提前获取路径,循环内复用:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import time

options = Options()
options.add_experimental_option("detach", True)
options.add_argument("--disable-logging")
options.add_argument("--disable-login-animations")
options.add_argument("--disable-notifications")
options.add_argument("--incognito")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--disable-blink-features=AutomationControlled")

if __name__ == "__main__":
    amount = 4
    # 提前获取ChromeDriver路径,避免循环内重复操作
    driver_path = ChromeDriverManager().install()
    drivers = []
    for _ in range(amount):
        driver = webdriver.Chrome(service=Service(driver_path), options=options)
        drivers.append(driver)
        time.sleep(1)
  • 检查目录权限
    右键C:\Users\jan\.wdm目录,选择「属性」→「安全」,确认当前用户拥有该目录的读写/完全控制权限,若缺失则添加对应权限。

  • 清理残留进程
    打开任务管理器,结束所有chromedriver.exe和未正常关闭的Chrome进程,再重新运行脚本。

  • 手动指定ChromeDriver路径(可选)
    手动下载对应版本的ChromeDriver并解压到固定目录,直接在代码中指定该路径,跳过WebDriver Manager的自动处理逻辑:

    # 替换为你手动解压的chromedriver.exe路径
    driver_path = "C:\\path\\to\\chromedriver.exe"
    driver = webdriver.Chrome(service=Service(driver_path), options=options)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 21:07:27