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

为何创建typing.py后出现selenium.webdriver无Chrome属性错误?

Selenium报错:AttributeError: partially initialized module 'selenium.webdriver' has no attribute 'Chrome' 原因分析

问题背景

原本运行正常的Selenium代码突然报错,涉及的脚本文件名为typing.py,代码如下:

from selenium import webdriver

url = "https://www.livechat.com/typing-speed-test/#/"

driver = webdriver.Chrome()

driver.get(url=url)

报错详情

driver = webdriver.Chrome()
             ^^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'selenium.webdriver' has no attribute 'Chrome' (most likely due to a circular import). Did you mean: 'chrome'?

当前项目目录结构

selenium
│   .env
│   amazon.py
│   cookie.py
│   linkedin.py
│   main.py
│   typing.py
│   test.py
│
└───__pycache__
        typing.cpython-312.pyc

报错核心原因

这个错误的根本问题是脚本所在的目录名和第三方Selenium库重名了:你的项目根目录是selenium,而你要导入的官方Selenium库也叫selenium。当Python执行from selenium import webdriver时,会优先加载当前目录下的selenium文件夹(将其视为本地模块),而不是你通过pip安装的官方Selenium库。

这个本地的selenium模块里并没有webdriver.Chrome这个属性,而且Python尝试加载它时,会和真正的Selenium库产生循环导入冲突,最终抛出这个错误。之前代码能正常运行,应该是你之前的项目目录结构里没有这个同名的selenium文件夹,后来调整目录结构后才触发了这个命名冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 07:26:04