Redhat7.9下Python3.6用pip安装boto3提示无匹配版本如何解决?
Boto3安装失败解决方案
错误根因
从报错日志的Name or service not known可以判断核心问题为三类:
- 服务器无法正常解析PyPI源域名,网络连通性异常
- 当前使用的pip 9.0.1版本过旧,无法适配新版PyPI源规则
- Python 3.6已停止官方维护,最新版boto3不再支持该版本,需要指定兼容版本安装
解决步骤
1. 排查修复网络连通性
- 先测试DNS解析是否正常,执行命令:
nslookup pypi.org - 如果返回解析失败,修改服务器DNS配置,编辑
/etc/resolv.conf添加公共DNS:
nameserver 8.8.8.8 nameserver 114.114.114.114
- 若为内网环境无法访问公网PyPI,可临时使用国内镜像源测试安装:
pip3 install boto3 -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
2. 升级pip到适配Python3.6的最高版本
pip 21.0及以上版本不再支持Python3.6,需指定升级到20.3.4版本:pip3 install --upgrade pip==20.3.4 -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
3. 安装适配Python3.6的boto3版本
boto3 1.19及以上版本不再支持Python3.6,指定安装最后兼容的1.18.65版本即可:pip3 install boto3==1.18.65 -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
离线环境特殊处理
如果服务器完全无法访问外部网络,可提前在同架构、同Python版本的联网机器上下载依赖包:pip3 download boto3==1.18.65 -d ./boto3_packages
将下载好的boto3_packages目录传输到目标服务器后执行离线安装:pip3 install --no-index --find-links=./boto3_packages boto3==1.18.65
内容的提问来源于stack exchange,提问作者Python Newbie
相关产品推荐
相关产品推荐

