首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法让AWS SAM与Python3.5.x一起工作

无法让AWS SAM与Python3.5.x一起工作
EN

Stack Overflow用户
提问于 2021-04-13 02:50:40
回答 1查看 944关注 0票数 0

我确信这个问题是由于我自己对Python和pip的无知所致,然而,我已经浏览了一下网络,并尝试了许多东西来使它工作,到目前为止,没有结果。

我有一个基于Bitbucket管道默认映像(version 2):atlassian/default-image:2的坞映像,它使用Python2.7.x。而SAM不起作用,我查看了AWS的文档,这说明SAM不再支持Python2.7.x,所以我从码头容器中删除了所有Python安装(在本地调试Bitbucket管道),并试图确保只安装了Python3和pip3 (我甚至设置了从/usr/bin/python/usr/bin/python3和从/usr/bin/pip/usr/bin/pip3的符号链接--不过,这似乎是一件愚蠢的事情)。

我还尝试使用Python3.6进行上述操作,因为错误消息(如下图所示)似乎显示了Python 'f-String‘语法,根据Python的文档,这个语法是在3.6中引入的。

我所做的一切似乎都没有用,我越看这个,我就越被困在一个似乎永无尽头的Python版本和linux包的网络中!

错误(和python版本)可以在这里看到:

代码语言:javascript
复制
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# 

我非常希望有一些正确的方法来确切地知道我需要哪个Python版本,以及一个安装和配置它的正确方法。

请帮助我:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-13 03:23:28

在大多数情况下,我建议只使用已经安装python 3的docker映像,而不是修改现有映像中的python安装或安装新映像。这个bitbucket页面讨论使用不同的基本图像。

还有一个有关如何使用python基映像的页面

除此之外,根据您想要如何使用SAM,您可能可以使用内建比特桶“管”来部署到SAM。这是一些管道的信息。。我认为这将绕过在您的构建中安装SAM的需要。

我本人没有使用过这个管道,但是我认为它的工作方式是在管道中构建部署工件文件,缓存它以便在以后的步骤中可用,然后将该文件设置为SAM管道用于部署它的输入。SAM管道在一个单独的容器中运行,因此它已经安装在该容器中。你只要把文件传进去。

最后,我从来没有使用过SAM,所以请稍加考虑,但是我没有看到在正式的AWS Linux安装文档在github页面上上使用正式的AWS Linux安装文档安装CLI的参考。我确实找到了本期,从中收集了以下信息:

  • 可以安装pip,但不建议安装
  • Python 3.5不受aws sam cli的支持
  • 如果您在说明中使用安装程序,听起来它将为您处理python版本控制。
  • 他们希望针对Python的单个版本,所以如果您使用pip,也许最新的或者第二个最新的Python版本可以工作。只是猜猜..。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67068093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档