简体   繁体   English

无法让 AWS SAM CLI 与 Python 3.5.x 一起使用

[英]Cannot get AWS SAM CLI to work with Python 3.5.x

I am certain that this issue is down to my own ignorance of Python and pip, however, I have scoured the net and tried many things to get this to work, so far, to no avail.我确信这个问题是由于我自己对 Python 和 pip 的无知,但是,我已经在网上搜索并尝试了很多方法来让它工作,到目前为止,无济于事。

I have a docker image based on the Bitbucket pipelines default image (version 2): atlassian/default-image:2 , which uses Python 2.7.x.我有一个基于 Bitbucket 管道默认图像(版本 2)的 docker 图像: atlassian/default-image:2 ,它使用 Python 2.7.x。 And SAM doesn't work with that, I looked at AWS' documentation and this said that the SAM CLI no longer supports Python 2.7.x, so I removed all Python installations from the docker container (debugging the Bitbucket pipeline locally) and attempted to make sure that there was only Python3 and pip3 installed (I even setup symlinks from /usr/bin/python to /usr/bin/python3 and from /usr/bin/pip to /usr/bin/pip3 - although, that seems like such a dumb thing to have to do). And SAM doesn't work with that, I looked at AWS' documentation and this said that the SAM CLI no longer supports Python 2.7.x, so I removed all Python installations from the docker container (debugging the Bitbucket pipeline locally) and attempted to确保只安装了 Python3 和 pip3(我什至设置了从/usr/bin/python/usr/bin/python3和从/usr/bin/pip/usr/bin/pip3 - 虽然,这看起来像不得不做这么愚蠢的事情)。

I also tried doing the above with Python 3.6, as the error message (shown below) seemed to show a Python 'f-String' syntax, which according to Python's docs was introduced in 3.6.我还尝试使用 Python 3.6 执行上述操作,因为错误消息(如下所示)似乎显示了 Python 'f-String' 语法,根据 Python 的文档,该语法是在 3.6 中引入的。

Nothing I do seems to work and the more I look at this, the more I get tied up in an seemingly never ending web of Python versions and linux packages!我所做的一切似乎都不起作用,而且我越看这个,我就越被扎在 Python 版本和 linux 包的看似永无止境的 web 中!

The error (and python versions) can be seen here:错误(和 python 版本)可以在这里看到:

root@eb3dc6ff9997:/localDebugRepo/infrastructure# pip3 install -U aws-sam-cli==1.22.0
Requirement already up-to-date: aws-sam-cli==1.22.0 in /usr/local/lib/python3.5/dist-packages
Requirement already up-to-date: jmespath~=0.10.0 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: boto3~=1.14 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: cookiecutter~=1.7.2 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: aws-sam-translator==1.35.0 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: aws-lambda-builders==1.3.0 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: tomlkit==0.7.0 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: dateparser~=0.7 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: requests==2.23.0 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: watchdog==0.10.3 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: PyYAML~=5.3 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: serverlessrepo==0.1.10 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: Flask~=1.1.2 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: chevron~=0.12 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: click~=7.1 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: docker~=4.2.0 in /usr/local/lib/python3.5/dist-packages (from aws-sam-cli==1.22.0)
Requirement already up-to-date: s3transfer<0.4.0,>=0.3.0 in /usr/local/lib/python3.5/dist-packages (from boto3~=1.14->aws-sam-cli==1.22.0)
Requirement already up-to-date: botocore<1.21.0,>=1.20.50 in /usr/local/lib/python3.5/dist-packages (from boto3~=1.14->aws-sam-cli==1.22.0)
Requirement already up-to-date: binaryornot>=0.4.4 in /usr/local/lib/python3.5/dist-packages (from cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: six>=1.10 in /usr/local/lib/python3.5/dist-packages (from cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: poyo>=0.5.0 in /usr/local/lib/python3.5/dist-packages (from cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: jinja2-time>=0.2.0 in /usr/local/lib/python3.5/dist-packages (from cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: MarkupSafe<2.0.0 in /usr/local/lib/python3.5/dist-packages (from cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: Jinja2<3.0.0 in /usr/local/lib/python3.5/dist-packages (from cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: python-slugify>=4.0.0 in /usr/local/lib/python3.5/dist-packages (from cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: jsonschema~=3.2 in /usr/local/lib/python3.5/dist-packages (from aws-sam-translator==1.35.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: setuptools in /usr/local/lib/python3.5/dist-packages (from aws-lambda-builders==1.3.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: wheel in /usr/local/lib/python3.5/dist-packages (from aws-lambda-builders==1.3.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: regex!=2019.02.19 in /usr/local/lib/python3.5/dist-packages (from dateparser~=0.7->aws-sam-cli==1.22.0)
Requirement already up-to-date: pytz in /usr/local/lib/python3.5/dist-packages (from dateparser~=0.7->aws-sam-cli==1.22.0)
Requirement already up-to-date: tzlocal in /usr/local/lib/python3.5/dist-packages (from dateparser~=0.7->aws-sam-cli==1.22.0)
Requirement already up-to-date: python-dateutil in /usr/local/lib/python3.5/dist-packages (from dateparser~=0.7->aws-sam-cli==1.22.0)
Requirement already up-to-date: chardet<4,>=3.0.2 in /usr/local/lib/python3.5/dist-packages (from requests==2.23.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: idna<3,>=2.5 in /usr/local/lib/python3.5/dist-packages (from requests==2.23.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.5/dist-packages (from requests==2.23.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: certifi>=2017.4.17 in /usr/local/lib/python3.5/dist-packages (from requests==2.23.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: pathtools>=0.1.1 in /usr/local/lib/python3.5/dist-packages (from watchdog==0.10.3->aws-sam-cli==1.22.0)
Requirement already up-to-date: itsdangerous>=0.24 in /usr/local/lib/python3.5/dist-packages (from Flask~=1.1.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: Werkzeug>=0.15 in /usr/local/lib/python3.5/dist-packages (from Flask~=1.1.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: websocket-client>=0.32.0 in /usr/local/lib/python3.5/dist-packages (from docker~=4.2.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: arrow in /usr/local/lib/python3.5/dist-packages (from jinja2-time>=0.2.0->cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: text-unidecode>=1.3 in /usr/local/lib/python3.5/dist-packages (from python-slugify>=4.0.0->cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: importlib-metadata; python_version < "3.8" in /usr/local/lib/python3.5/dist-packages (from jsonschema~=3.2->aws-sam-translator==1.35.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: pyrsistent>=0.14.0 in /usr/local/lib/python3.5/dist-packages (from jsonschema~=3.2->aws-sam-translator==1.35.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: attrs>=17.4.0 in /usr/local/lib/python3.5/dist-packages (from jsonschema~=3.2->aws-sam-translator==1.35.0->aws-sam-cli==1.22.0)
Requirement already up-to-date: typing-extensions; python_version < "3.8" in /usr/local/lib/python3.5/dist-packages (from arrow->jinja2-time>=0.2.0->cookiecutter~=1.7.2->aws-sam-cli==1.22.0)
Requirement already up-to-date: zipp>=0.5 in /usr/local/lib/python3.5/dist-packages (from importlib-metadata; python_version < "3.8"->jsonschema~=3.2->aws-sam-translator==1.35.0->aws-sam-cli==1.22.0)
You are using pip version 8.1.1, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@eb3dc6ff9997:/localDebugRepo/infrastructure# python --version
bash: /usr/bin/python: No such file or directory
root@eb3dc6ff9997:/localDebugRepo/infrastructure# pip --version
bash: /usr/bin/pip: No such file or directory
root@eb3dc6ff9997:/localDebugRepo/infrastructure# python3 --version
Python 3.5.2
root@eb3dc6ff9997:/localDebugRepo/infrastructure# pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
root@eb3dc6ff9997:/localDebugRepo/infrastructure# sam --version
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 7, in <module>
    from samcli.cli.main import cli
  File "/usr/local/lib/python3.5/dist-packages/samcli/cli/main.py", line 86
    cmdline_args_log += f"--{key} "
                                  ^
SyntaxError: invalid syntax
root@eb3dc6ff9997:/localDebugRepo/infrastructure# 

I would really like there to be some sane way to know exactly which Python version I need and a sane way to install and configure it.真的很想有一些理智的方法来确切地知道我需要哪个 Python 版本,以及一种理智的方法来安装和配置它。

Please help me:)请帮我:)

In most cases, instead of modifying the python installation in an existing image or installing a new one, I would recommend just using a docker image that already has python 3 installed.在大多数情况下,我建议仅使用已安装 python 3 的 docker 映像,而不是修改现有映像中的 python 安装或安装新映像。 This bitbucket page talks about using different base images. 这个 bitbucket 页面讨论了使用不同的基本图像。

There's also a page about using a python base image spectifically .还有一个关于具体使用 python 基础镜像的页面。

Aside from this, depending on how you want to use SAM, you may be able to use the builtin Bitbucket "pipe" for deploying to SAM instead.除此之外,根据您希望如何使用 SAM,您可以使用内置的 Bitbucket “管道”来部署到 SAM。 Here is some info on pipes. 这是有关管道的一些信息。 . . I think this would bypass the need to install SAM in your build.认为这将绕过在您的构建中安装 SAM 的需要。

I haven't used that particular pipe myself but the way I think it works is you build your deploy artifact file in your pipeline, caching it so it's available in future steps, then you set that file as the input for the SAM pipe to deploy it.我自己没有使用过特定的 pipe,但我认为它的工作方式是在管道中构建部署工件文件,将其缓存以便在以后的步骤中可用,然后将该文件设置为 SAM pipe 的输入以进行部署它。 The SAM pipe runs in a separate container, so it's already installed in that container. SAM pipe 在单独的容器中运行,因此它已经安装在该容器中。 You just pass in the file.您只需传入文件。

Finally, I have never used SAM, so take this with a grain of salt, but I don't see a reference to installing the CLI with pip either on the official AWS Linux installation docs or on the github page .最后,我从来没有使用过 SAM,所以对此持保留态度,但在官方 AWS Linux 安装文档ZBF215181B414052D54437B37B3 页面上,我没有看到使用pip安装 CLI 的参考。 I did find this issue , from which I glean the following:我确实发现了这个问题,从中我收集了以下信息:

  • pip installation is possible but not recommended pip安装是可能的,但不推荐
  • Python 3.5 is not supported by aws sam cli aws sam cli 不支持 Python 3.5
  • If you use the installer in the instructions, it sounds like it will take care of the python versioning for you.如果您使用说明中的安装程序,听起来它会为您处理 python 版本控制。
  • They would like to target a single version of Python, so if you use pip, maybe the latest or 2nd latest Python version will work.他们希望针对 Python 的单个版本,所以如果您使用 pip,也许最新或第二个最新的 Python 版本可以工作。 Just a guess...只是猜测...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM