ModuleNotFoundError: No module named 'pyodbc'. Cannot find module. When deploying python Azure functions from CI/CD pipeline

Shreyash Kalushte 20 Reputation points
2025-05-22T03:58:31.68+00:00

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

User's image

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!!!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,930 questions
{count} votes

Accepted answer
  1. Praveen Kumar Gudipudi 1,875 Reputation points Microsoft External Staff Moderator
    2025-05-30T16:21:39.27+00:00

    Hello Shreyash,

    Thankyou for posting function app status.

    It might seem unusual, but Python functions are now working correctly in version 3.11.

    We ran the pipeline multiple times to TEST env as per our schedule, and in one of the runs, the functions unexpectedly executed without errors. We then deployed the same code to UAT, and the functions continued to work as intended - despite no changes being made to the code for the functions

    This behavior appears to have resolved itself without any modifications on our end.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.