I have Python 3.9 code and an Azure DevOps pipeline where it builds and deploy the code to Azure Functions.
The pipeline has been working fine for the past several weeks (it’s new) and there was no deployment recently until I had to fix a few lines of code, then I pushed to Azure Repo which triggers the pipeline. But this time the Function crashed when triggered; this is the error message:
Exception: ModuleNotFoundError: No module named ‘holidays’. Cannot
find module. Please check the requirements.txt file for the missing
module.
This is my requirements.txt file, which clearly states the holidays module version.
azure-functions
azure-functions-durable
azure-identity==1.14.0
azure-keyvault-secrets==4.7.0
azure-storage-blob==12.17.0
dotmap==1.3.30
holidays==0.32
json5==0.9.14
numpy==1.25.2
pandas==2.1.0
pyodbc==4.0.39
pytz==2023.3.post1
requests_oauthlib==1.3.1
sqlalchemy==2.0.20
If I deploy from VS Code using Azure Functions extension, the code runs fine without any error, so I’m suspecting that the DevOps pipeline is acting weird (despite nobody changed anything on the YAML file)
This is my azure-pipelines.yml file
trigger:
- main
variables:
azureSubscription: '<REDACTED>'
functionAppName: <REDACTED>
functionAppProjectPath: $(System.DefaultWorkingDirectory)/
pythonVersion: '3.9'
vmImage: ubuntu-latest
stages:
- stage: Build
displayName: Build Stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImage)
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: $(pythonVersion)
- bash: |
pip install -r requirements.txt
workingDirectory: $(functionAppProjectPath)
displayName: 'Install dependencies'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: $(functionAppProjectPath)
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy Stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: <REDACTED>
pool:
vmImage: $(vmImage)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@2
displayName: 'Azure Function App Deploy'
inputs:
appType: functionAppLinux
appName: $(functionAppName)
azureSubscription: $(azureSubscription)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
I don’t know what’s wrong here. Hoping someone could point the problem out. Thanks.
2
Answers
In order to resolve
ModuleNotFound error
make sure you use the step below correctly in your Azure Devops yaml pipeline:-Make sure you are selecting correct Branch that includes your Function code for your Pipeline:-
Azure Repository:-
Complete yaml pipeline code for Durable Function:-
My requirements.txt:-
Sample Durable Function code:-
Sample Http Trigger code:-
Sample yaml code for Http Trigger code:-
Output:-
For Durable Function:-
holidays
package is installed correctly:-For Http Trigger:-
holidays
package is installed correctly:-I’m using the similar yaml to SiddheshDesai and it works fine. If you still have the same error after trying
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
, try the steps below to narrow down the issue.az functionapp deployment source config-zip -g <resource_group> -n <app_name> --src <zip_file_path>
.pip install
and see ifholidays
is installed like:holidays
in the log, try to runpip install holidays==0.32
in your pipeline and check if it works.