安装aws-cli时遭遇pip报错,寻求解决方案
解决AWS CLI安装时的
ValueError: non-local file URIs are not supported问题 问题描述
尝试使用以下命令安装AWS CLI:
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
添加sudo -H参数后仍然失败:
sudo -H ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
两次安装均触发核心错误:
ValueError: non-local file URIs are not supported on this platform: 'file://.'
已确认pip为最新版本(23.3.1),但问题未解决。
原因分析
awscli-bundle的install脚本中使用了file://.这种相对路径的文件URI,新版pip(尤其是macOS平台)对文件URI的格式校验更严格,不支持这种非本地的相对路径写法。
解决方法
方法1:修改awscli-bundle的install脚本
- 打开awscli-bundle目录下的
install脚本 - 找到
_install_setup_deps函数中的pip调用行(大致在第167行附近):run( [python, '-m', 'pip', 'install', '--no-binary', ':all:', '--no-cache-dir', '--no-index', '--find-links', f'file://{path}', req] ) - 将
f'file://{path}'替换为绝对路径写法,或者直接使用本地路径:- 绝对路径写法:
f'file://{os.path.abspath(path)}'(需确保脚本顶部已导入import os) - 本地路径写法:直接用
path替代(即当path为.时,使用./)
- 绝对路径写法:
- 保存修改后,重新运行原安装命令。
方法2:改用官方推荐的现代安装方式
awscli-bundle是旧版安装方式,官方现在推荐更简单的安装途径:
- macOS用Homebrew安装:
brew install awscli - 用pip直接安装:
pip3 install awscli --upgrade --user
内容的提问来源于stack exchange,提问作者Aditya Garde
相关产品推荐
相关产品推荐

