AWS Amplify部署失败:typing-extensions版本冲突求助
AWS Amplify部署依赖冲突问题解决建议
问题详情
部署报错:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
aws-sam-cli 1.55.0 requires typing-extensions==3.10.0.0, but you have typing-extensions 4.7.1 which is incompatible.
已尝试但无效的操作:
- 将pipenv降级至2023.8.26版本
- 在amplify.yml中添加
python3 -m pip install typing-extensions==3.10.0.0命令 - 尝试降级aws-sam-cli、boto3、botocore及awscli,因awscli依赖botocore导致冲突失败
报错时的amplify.yml后端配置:
backend: phases: preBuild: commands: - ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3 - ln -fs /usr/local/bin/python3.8 /usr/bin/python3 - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade setuptools wheel - python3 -m pip install --upgrade pipenv build: commands: - amplifyPush --simple
解决方案
1. 强制锁定typing-extensions版本并指定pipenv固定版本
修改amplify.yml的preBuild阶段,直接指定pipenv的成功版本,同时强制覆盖安装目标版本的typing-extensions:
backend: phases: preBuild: commands: - ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3 - ln -fs /usr/local/bin/python3.8 /usr/bin/python3 - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade setuptools wheel - python3 -m pip install pipenv==2023.8.26 # 直接指定成功版本,避免自动升级 - python3 -m pip install typing-extensions==3.10.0.0 --force-reinstall # 强制覆盖现有版本 build: commands: - amplifyPush --simple
2. 用pipenv虚拟环境隔离依赖
通过Pipfile锁定项目依赖,让构建过程在隔离的虚拟环境中执行,避免全局包干扰:
- 本地生成指定版本的Pipfile:
pipenv install --python 3.8 pipenv install typing-extensions==3.10.0.0 pipenv install aws-sam-cli==1.55.0 # 添加其他项目所需依赖
- 修改amplify.yml,使用虚拟环境执行部署:
backend: phases: preBuild: commands: - ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3 - ln -fs /usr/local/bin/python3.8 /usr/bin/python3 - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade setuptools wheel - python3 -m pip install pipenv==2023.8.26 build: commands: - pipenv install --deploy # 基于Pipfile.lock安装依赖 - pipenv run amplifyPush --simple # 在虚拟环境中执行部署命令
3. 升级aws-sam-cli至兼容高版本typing-extensions的版本
aws-sam-cli 1.55.0版本较旧,后续版本已兼容更高版本的typing-extensions,直接升级即可:
backend: phases: preBuild: commands: - ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3 - ln -fs /usr/local/bin/python3.8 /usr/bin/python3 - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade setuptools wheel - python3 -m pip install --upgrade pipenv==2023.8.26 - python3 -m pip install --upgrade aws-sam-cli # 升级到最新兼容版本 build: commands: - amplifyPush --simple
内容的提问来源于stack exchange,提问作者Flobbinhood
相关产品推荐
相关产品推荐

