使用pip3升级Python依赖遇SSL错误:UNSAFE_LEGACY_RENEGOTIATION_DISABLED
问题描述
我正在使用QGIS 3.34.9附带安装的OSGeo4W(基于Python 3.12.4)升级Python依赖,主要是remotior-sensus。按照官方文档步骤操作,已下载依赖但无法安装。执行命令:
pip3 install --upgrade remotior-sensus scikit-learn torch
后出现以下错误:
Requirement already satisfied: remotior-sensus in c:\progra~1\qgis33~1.9\apps\python312\lib\site-packages (0.3.5) WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/remotior-sensus/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/remotior-sensus/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/remotior-sensus/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/remotior-sensus/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/remotior-sensus/ Could not fetch URL https://pypi.org/simple/remotior-sensus/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/remotior-sensus/ (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))) - skipping WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/scikit-learn/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/scikit-learn/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/scikit-learn/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/scikit-learn/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))': /simple/scikit-learn/ Could not fetch URL https://pypi.org/simple/scikit-learn/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/scikit-learn/ (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))) - skipping ERROR: Could not find a version that satisfies the requirement scikit-learn (from versions: none) ERROR: No matching distribution found for scikit-learn Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)'))) - skipping
解决办法
这个错误源于Python 3.12默认禁用了不安全的旧版SSL协商机制,导致无法正常连接PyPI。以下是几种可行的解决方案:
方法1:临时设置环境变量绕过SSL校验
打开OSGeo4W Shell,依次执行以下命令,再运行pip安装:
set SSL_CERT_FILE=C:\PROGRA~1\QGIS33~1.9\apps\Python312\Lib\site-packages\certifi\cacert.pem set PYTHONHTTPSVERIFY=0 set SSL_ENABLE_EARLY_DATA=0 pip3 install --upgrade remotior-sensus scikit-learn torch
方法2:配置pip信任PyPI主机
- 在用户目录下创建
pip文件夹,路径示例:C:\Users\[你的用户名]\pip - 在该文件夹内新建
pip.ini文件,写入以下内容:
[global] trusted-host = pypi.org files.pythonhosted.org
保存后重新运行pip安装命令即可。
方法3:使用国内PyPI镜像源
直接指定国内镜像源,绕开SSL协商问题,执行命令:
pip3 install --upgrade remotior-sensus scikit-learn torch -i https://pypi.tuna.tsinghua.edu.cn/simple
方法4:手动安装本地已下载的依赖包
既然已下载好依赖包,直接用pip安装本地文件,替换命令中的xxx为实际版本号和文件路径:
pip3 install [本地路径]\remotior-sensus-xxx.whl [本地路径]\scikit-learn-xxx.whl [本地路径]\torch-xxx.whl
内容的提问来源于stack exchange,提问作者user25730
相关产品推荐
相关产品推荐

