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

ImportError:无法从部分初始化的selenium模块导入webdriver求助

问题描述

运行以下Python代码时出现错误:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time

# https://sites.google.com/chromium.org/driver/

service = Service(executable_path="chromedriver.exe")
driver = webdriver.Chrome(service=service)

driver.get("https://google.com")

time.sleep(2)

driver.quit()

错误信息:

ImportError: 无法从部分初始化的模块 'selenium' 中导入名称 'webdriver'

解决方案
  • 检查脚本文件名,绝对不能叫selenium.py,这会和官方selenium模块重名,导致导入逻辑混乱。
  • 卸载重装selenium:执行pip uninstall selenium彻底卸载,再用pip install selenium安装最新稳定版。
  • 清理项目目录里的冗余文件,比如自动生成的selenium.pyc或者同名文件夹,删除后重新运行脚本。

内容的提问来源于stack exchange,提问作者Mr.Dumb

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 09:17:33