使用 python3.7 版本的 aws-sam-cli 包的 pip 安装

pip install of aws-sam-cli package with python3.7 version

在下面的 docker 文件中:

FROM alpine:latest

ENV HOME /home/samcli
ENV PATH $HOME/.local/bin:$PATH

RUN mkdir /root/bin /aws; \
    apk add --no-cache groff less bash python jq curl py-pip tzdata

RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime

RUN apk add --no-cache --virtual .build-deps gcc python2-dev python3-dev linux-headers musl-dev && \
    pip install --upgrade pip; \
    adduser samcli -Du 5566; \
    chown -R samcli $HOME;

USER samcli

WORKDIR $HOME

RUN pip install --user --upgrade awscli aws-sam-cli;

USER root

RUN apk del .build-deps; \
    rm -rf /var/cache/apk/*

Layer(RUN pip install --user --upgrade awscli aws-sam-cli;) 正在安装 python 2.7,尽管图像已安装 python3.7。

我在安装 python 软件包时看到以下弃用错误:

Step 9/11 : RUN pip install --user --upgrade awscli aws-sam-cli;

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/


如何使用 python3.7 安装 aws 包? 因为下面的命令正在使用 python2

pip install --user --upgrade awscli aws-sam-cli;

我建议使用基于 alpine 的 python 官方镜像,这样您就不需要维护和安装 python 版本。下面的基本图像基于 alpine 3.9python version is 3.7

FROM python:3.7-alpine3.9

ENV HOME /home/samcli
ENV PATH $HOME/.local/bin:$PATH
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN apk add --no-cache --virtual .build-deps python2-dev  python3-dev gcc linux-headers musl-dev && \
    adduser samcli -Du 5566; \
    chown -R samcli $HOME;
RUN apk add --no-cache groff less bash jq curl py-pip tzdata
USER samcli

WORKDIR $HOME

RUN pip install --user --upgrade awscli aws-sam-cli;
USER root

RUN apk del .build-deps; \
    rm -rf /var/cache/apk/*