已经安装已经安装了Selenium库和适配的浏览器驱动(如ChromeDriver),查询结果:
C:\Users\Administrator>python -c "import selenium; print(selenium.__file__)"
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\__init__.py
如下的4句就出现了 后面的多个错误
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/xmx-test/waigua20240905-2.py", line 1, in <module>
from selenium import webdriver
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\__init__.py", line 20, in <module>
from .chrome.webdriver import WebDriver as Chrome # noqa
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 18, in <module>
from selenium.webdriver.chromium.webdriver import ChromiumDriver
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 18, in <module>
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chromium\remote_connection.py", line 18, in <module>
from selenium.webdriver.remote.remote_connection import RemoteConnection
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 27, in <module>
import urllib3
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\__init__.py", line 39, in <module>
"urllib3 v2.0 only supports OpenSSL 1.1.1+, currently "
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with OpenSSL 1.1.0j 20 Nov 2018. See: https://github.com/urllib3/urllib3/issues/2168
您的错误信息显示,您当前使用的Python环境中,`urllib3`库的版本不兼容所编译的OpenSSL版本。这通常是因为您的Python安装较旧。以下是修复此问题的步骤:
1. **更新Python**:
- 卸载现有的Python版本,并从Python官方网站下载并安装最新版本的Python。
2. **更新相关库**:
- 使用命令更新`pip`:
python -m pip install --upgrade pip
- 重新安装或升级`urllib3`和其他相关库:
pip install --upgrade urllib3 selenium
3. **检查OpenSSL版本**:
- 安装最新版本的Python后,确保更新的Python附带支持OpenSSL 1.1.1或更高版本。
4. **测试代码**:
- 在确保所有软件均已更新后,尝试再次运行您的代码。
如果以上步骤没有解决问题,请进一步检查您的环境变量是否设置正确,并确认您没有多个Python环境彼此冲突。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
|