Deploying Python functions using my CI/CD pipeline succeeds. But when the functions are invoked after that the following error is thrown
Type |
Message |
Information |
Executing 'Functions.collect_copy_metrics' (Reason='This function was programmatically called via the host APIs.') |
Error |
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 546, 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 220, 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/collect_copy_metrics/collect_copy_metrics.py", line 5, in <module> import pyodbc |
|
|
Strangely enough, when I deploy the functions using the Azure extension from my VSCode, the function invocations are working as intended and no longer throw the ModuleNotFoundError error

The ModuleNotFoundError error only arises when I deploy the functions from the yml pipeline.
This is how my deployment.yml task looks like
- task: AzureFunctionApp@2
displayName: 'AF: Deploy New Azure Functions'
condition: and(succeeded(), eq('${{ parameters.deploy_af }}', 'true'))
inputs:
connectedServiceNameARM: 'spName'
appType: 'functionAppLinux'
isFlexConsumption: true
appName: 'appName'
package: '$(Build.ArtifactStagingDirectory)/af_001/drop/*.zip'
And this is how the build is created
jobs:
- job: AFBuild
displayName: Build AF Artifact
pool: Self Hosted Pool
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.11
- bash: 'pip install --target="./azurefunctions/af-001/.python_packages/lib/site-packages" -r ./azurefunctions/af-001/requirements.txt'
displayName: 'Install Requirements'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)/azurefunctions/af-001'
includeRootFolder: false
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
My requirements.txt file
azure-functions
azure_data_tables==12.4.3
pyodbc==5.2.0
python-dateutil==2.9.0
google-auth==2.38.0
Downgrading the function app from python 3.11 to 3.10 works in our case i.e. we don't get the ModuleNotFoundError anymore for pyodbc, but since we have multiple functions deployed in production which were developed on python 3.11, downgrading is not really an option for us.
Any help on this matter would be greatly appreciated!!!