使用GitHub上的serverlesspythonrequirements插件下载依赖项操作抛出“找不到Python 3.7”

2024-04-18 08:28:18 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的工作流程:deploy.yml

on:
  push:
    branches: [develop, main]
env:
  name: project-name
  region: my-region
jobs:
  env:
    name: Load environment vars from .env files
    runs-on: ubuntu-latest
    steps:
      <omitted>
  deploy:
    name: Deploy|${{needs.env.outputs.environment}}
    needs: env
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Configure AWS Credentials
        id: creds
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
          aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
          aws-region: ${{needs.env.outputs.region}}
      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: '3.7.7'
      - name: Installs Serverless plugins and Deploy
        uses: serverless/github-action@v1.53.0
        with:
          args: -c "serverless plugin install --name serverless-python-requirements && serverless deploy --verbose"
          entrypoint: /bin/bash
        env:
          SLS_DEBUG: '*'
          AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
          AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
          environment: ${{needs.env.outputs.environment}}

这是我的serverless.yml:

service: my-service

provider:
  name: aws
  runtime: python3.7

package:
  individually: True

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: false

functions:
  etl:
    name: ${env:environment}-etl-lambda
    handler: etl/lambda_functions/etl_lambda_function.lambda_handler
    module: etl/lambda_functions
    package:
      include:
        - ./etl

项目结构:

etl/
    lambda_functions/
        etl_lambda_function.py
        requirements.txt

每当操作运行时,我都会得到Error: python3.7 not found! Try the pythonBin option.

因此,我更新了我的serverless.yml,以引用opt/目录中的python安装(阅读更多关于here):

custom:
  pythonRequirements:
    dockerizePip: false
    pythonBin: /opt/hostedtoolcache/Python/bin/python3.7

但是现在我得到了Error: /opt/hostedtoolcache/Python/bin/python3.7 not found! Try the pythonBin option.

我不确定如何引用actions/setup-python@v2安装Python的位置,以及在serverless-python-requests中引用该位置

关于无服务器python请求,我还看到了一些其他问题,但没有提到在GitHub操作上运行时的问题

我也尝试过设置dockerizePip: true,但是我得到了Errorr: cannot find docker错误

非常感谢您的反馈


Tags: lambdakeynameenvawsactionsaccessenvironment
1条回答
网友
1楼 · 发布于 2024-04-18 08:28:18

docker容器可能有错误,而yml文件没有。或者在Dockerfile中断开与yml的连接

Dockerfile应该有如下内容

RUN apt-get -qq upgrade -y python3.7 

这是Ubuntu的。如果您是第一次尝试设置,则可能缺少某些环境设置

相关问题 更多 >