pyodbc module not found error in Azure function app deploying with azure ci/cd pipeline
I am deploying my azure python function app through azure ci/cd pipeline.yml.
My requirement.txt has pyodbc in it and i see that during build the pyodbc module is installed and wrapped in artifact.
I have tried both version of azurefunctionapp task but same error My pipeline yaml is as follows
Python Function App to Linux on Azure
Build a Python function app and deploy it to Azure as a Linux function app.
Add steps that analyze code, save build artifacts, deploy, and more:
https://docs.microsoft.com/azure/devops/pipelines/languages/python
trigger:
- main
variables:
Azure Resource Manager connection created during pipeline creation
azureSubscription: <hided to avoid problem>
Function app name
functionAppName: 'aframa'
Agent VM image name
vmImageName: 'ubuntu-latest'
Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)'
projectRoot: $(System.DefaultWorkingDirectory)/src/fa-event-driven-app
stages:
- stage: Build displayName: Build stage jobs:
- job: Build displayName: Build pool: vmImage: $(vmImageName) steps:
- task: UsePythonVersion@0 displayName: 'Use Python 3.11' inputs: versionSpec: '3.11' addToPath: true architecture: 'x64'
- bash: | if [ -f extensions.csproj ] then
fi pip3 install --upgrade pip pip3 install --upgrade setuptools pip3 install --target="./.python_packages/lib/site-packages" -r $(projectRoot)/requirements.txt pip3 uninstall pyodbc pip install --target="./.python_packages/lib/site-packages" --no-binary :all: pyodbc workingDirectory: $(workingDirectory) displayName: 'Build extensions'dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
- task: ArchiveFiles@2 displayName: 'Archive files' inputs: rootFolderOrFile: '$(projectRoot)' includeRootFolder: false archiveType: zip archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip artifact: drop
- job: Build displayName: Build pool: vmImage: $(vmImageName) steps:
- stage: Deploy displayName: Deploy stage dependsOn: Build condition: succeeded() jobs:
- deployment: Deploy displayName: Deploy environment: 'development' pool: vmImage: $(vmImageName) strategy: runOnce:
deploy: steps: - task: UsePythonVersion@0 inputs: versionSpec: '3.11' addToPath: true architecture: 'x64' - task: AzureFunctionApp@2 displayName: 'Azure functions app deploy' inputs: connectedServiceNameARM: 'afraconn' appType: 'functionAppLinux' appName: '$(functionAppName)' package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip' runtimeStack: 'PYTHON|3.11' deploymentMethod: 'runFromPackage' # - task: AzureFunctionApp@1 # displayName: 'Azure functions app deploy' # inputs: # azureSubscription: 'afraconn' # appType: 'functionAppLinux' # appName: 'aframa' # package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip' # runtimeStack: 'PYTHON|3.11' # # startUpCommand: 'func azure functionapp publish aframa'
- deployment: Deploy displayName: Deploy environment: 'development' pool: vmImage: $(vmImageName) strategy: runOnce:
my requirement.txt
azure-functions
requests==2.31.*
azure-storage-blob==12.10.0
azure-eventgrid
azure-core
pandas
pyodbc==5.0.0
azure.identity
pymssql
azure-keyvault-secrets
azure-mgmt-datafactory
great_expectations==0.18.9
But when it deployed in azure function app and i run my function it is throwing pyodbc module not found
Result: Failure Exception: ModuleNotFoundError: No module named 'pyodbc'. Cannot find module. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound. Current sys.path: ['/tmp/functions\standby\wwwroot', '/home/site/wwwroot/.python_packages/lib/site-packages', '/azure-functions-host/workers/python/3.11/LINUX/X64', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages'] Stack: File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 437, in _handle__function_load_request func = loader.load_function( ^^^^^^^^^^^^^^^^^^^^^ File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 49, in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/loader.py", line 197, in load_function mod = importlib.import_module(fullmodname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/site/wwwroot/func-event-grid-notifier-app/init.py", line 5, in <module> import pyodbc