1

I have a Python flask app that I want to deploy to an Azure Web App.

For some reason the venv that gets created during the build is not keeping the packages that get installed and I don't understand why. As an example, the requirements.txt has openai==1.12.0 in it.
The build job prints Successfully installed [...] openai-1.12.0 [...]. That sounds like it should be fine.

Then in the Azure shell of the web app after the deploy is successful I run pip list(with the antenv virtual enviroment active) to see what is installed and get a list with no openai. If I list the contents of the venv folder it contains all packages that I wanted installed...

This is the yaml for the build job:

          - script: |
              sudo apt-get install python3.11-dev portaudio19-dev
              ls
              python -m venv antenv
              source antenv/bin/activate
              python -m pip install --upgrade pip
              pip install -r ./requirements.txt
            workingDirectory: "$(projectRoot)"
            displayName: "Install requirements"

I also tried to change the pip install line to
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
with no luck, the packages are in that folder but not in use by the venv.
Am I doing anything obviously wrong? Any tips?

Edit: This is my pip list out put after the pip install steps:


h11                    0.14.0
httpcore               1.0.3
httpx                  0.26.0
idna                   3.6
isodate                0.6.1
itsdangerous           2.1.2
Jinja2                 3.1.3
langdetect             1.0.9
MarkupSafe             2.1.5
msrest                 0.7.1
numpy                  1.26.4
oauthlib               3.2.2
openai                 1.12.0
openpyxl               3.1.2
pandas                 2.2.0
pip                    24.0
PyAudio                0.2.14
pydantic               2.6.1
pydantic_core          2.16.2
python-dateutil        2.8.2
python-dotenv          1.0.1
pytz                   2024.1
requests               2.31.0
requests-oauthlib      1.4.0
setuptools             65.5.0
six                    1.16.0
sniffio                1.3.0
SpeechRecognition      3.10.1
tqdm                   4.66.2
typing_extensions      4.9.0
tzdata                 2024.1
urllib3                2.2.0
waitress               3.0.0
Werkzeug               3.0.1
WTForms                3.1.2

And this is the result from running pip list in the venv in the Azure SSH shell:

Package              Version
-------------------- -------
appsvc-code-profiler 1.0.0
blinker              1.7.0
click                8.1.7
debugpy              1.8.1
distlib              0.3.8
filelock             3.13.1
Flask                3.0.2
gunicorn             21.2.0
itsdangerous         2.1.2
Jinja2               3.1.3
markdown-it-py       3.0.0
MarkupSafe           2.1.5
mdurl                0.1.2
objprint             0.2.3
orjson               3.8.10
packaging            24.0
pip                  24.0
platformdirs         4.2.0
psutil               5.9.8
Pygments             2.17.2
rich                 13.7.1
setuptools           69.1.0
subprocess32         3.5.4
virtualenv           20.25.1
vizplugins           0.1.3
viztracer            0.15.6
Werkzeug             3.0.1
wheel                0.42.0
2
  • What does this have to do with flask? Commented Apr 26, 2024 at 13:17
  • Nothing really, true Commented Apr 29, 2024 at 5:12

3 Answers 3

1

You can use below Azure Devops yaml code to get the pip list after the pip install task in the build:-

My requirements.txt:-

Flask==2.0.2
gunicorn
PyYAML

Azure Devops yaml code:-

trigger:
- main

variables:
  azureServiceConnectionId: '23xxxxxxxxc036a5'
  webAppName: 'valleywebapp98'

  vmImageName: 'ubuntu-latest'
  environmentName: 'valleywebapp98'

  projectRoot: $(System.DefaultWorkingDirectory)
  pythonVersion: '3.10'

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: BuildJob
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '$(pythonVersion)'
      displayName: 'Use Python $(pythonVersion)'

    - script: |
        python -m venv antenv
        source antenv/bin/activate
        python -m pip install --upgrade pip
        pip install setup
        pip install -r requirements.txt
        pip list
      workingDirectory: $(projectRoot)
      displayName: "Install requirements"

    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(projectRoot)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      displayName: 'Upload package'
      artifact: drop

- stage: Deploy
  displayName: 'Deploy Web App'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: DeploymentJob
    pool:
      vmImage: $(vmImageName)
    environment: $(environmentName)
    strategy:
      runOnce:
        deploy:
          steps:

          - task: UsePythonVersion@0
            inputs:
              versionSpec: '$(pythonVersion)'
            displayName: 'Use Python version'

          - task: AzureWebApp@1
            displayName: 'Deploy Azure Web App : valleywebapp98'
            inputs:
              azureSubscription: $(azureServiceConnectionId)
              appName: $(webAppName)
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip

Output:-

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

I did that before, see the update
I see the packages are getting listed in the pip list script, Which packages are missing?
Basically all of the ones not included in the azure container image. for example openai and numpy . See the lower pip list for what's included in the venv in the Azure container.
This just seems to be the way Azure containers work, the reason the web app is not working is something else most likely
Is the app running properly after the deployment?, Inspite of missing packages in pip list?
|
0

Turns out it just looks like packages are missing in the Azure ssh shell. My problem was that my entry point was not found by Azure and I had to specify it to get my app running. The actual application is running with the correct packages installed even though pip list looks like it does not have all packages.

Comments

0

if requirement file not installing in deployment

or force install requirements.txt while deployment

set environment variable : SCM_DO_BUILD_DURING_DEPLOYMENT=true in web app portal.

Help Rebuild application while every re-deployment

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.