正在将简单Flask应用程序部署到Azure应用程序服务- ModuleNotFoundError:没有名为“requests”的模块

qcbq4gxm  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(119)

我正在尝试将一个简单的flask应用程序部署到Azure应用服务容器,但是当从github存储库部署时,我收到错误消息ModuleNotFoundError: No module named 'requests'
我在项目中使用pip freeze〉requirements.txt填充了requirements.txt文件。
requirements.txt

bcrypt==4.0.1
cffi==1.15.1
click==8.1.3
colorama==0.4.6
cryptography==38.0.4
dnspython==2.2.1
Flask==2.2.2
Flask-Cors==3.0.10
itsdangerous==2.1.2
Jinja2==3.1.2
jwt==1.3.1
MarkupSafe==2.1.1
pathlib==1.0.1
pycparser==2.21
pymongo==4.3.3
six==1.16.0
Werkzeug==2.2.2
Wheelhouse==0.1.4

我的管道yml文件:

name: Build and deploy Python app to Azure Web App - b00782310-com774

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
    SCM_DO_BUILD_DURING_DEPLOYMENT: 1

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Python version
        uses: actions/setup-python@v1
        with:
          python-version: '3.8'

      # - name: Create and start virtual environment
      #   run: |
      #     python -m venv venv
      #     source venv/bin/activate
      
      - name: Install dependencies
        run: pip install -r requirements.txt

      # Optional: Add step to run tests here (PyTest, Django test suites, etc.)

      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !venv/
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .

      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: 'b00782310-com774'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_AF561207AFB44DF1B5B6F54DFA612E98 }}

任何帮助都将不胜感激,尝试了很多网上提示,但不能让它工作。

myzjeezk

myzjeezk1#

您是否尝试过在需求中包含“请求”:

...
pycparser==2.21
pymongo==4.3.3
requests == 2.28.1
six==1.16.0
Werkzeug==2.2.2
...

或者直接将它添加到您的yml依赖项中,即

- name: Install dependencies
  run: |
        pip install -r requirements.txt
        python -m pip install requests

这对我来说也很新鲜--但希望这能有所帮助。
在app-service msft github repo too中有一些不错的帮助

相关问题