skip to Main Content

I published a python 3.10 function app to azure, locally the function runs successfully.

The deployment is successful, but executing the function on cloud, returning the following error:

Result: Failure Exception: ModuleNotFoundError: No module named 'cv2'. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound Stack: File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 387, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 48, in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call return func(*args, **kwargs) File "/azure-functions-...

The requirements.txt file exists in the root folder and contains list of all packages including cv

opencv-contrib-python==4.5.5.62

opencv-python==4.5.5.62

(I can see it in Azure portal -> Function App -> App Files)

What am I missing?

2

Answers


  1. Chosen as BEST ANSWER

    The issue was that these two configurations were in the function app.

    Removing them enabled the installation of packages specified in the requirements.txt file:

    {
            "name": "ENABLE_ORYX_BUILD",
            "value": "false",
            "slotSetting": false
    },
    {
            "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
            "value": "false",
            "slotSetting": false
    }
    

  2. I have created a python 3.10 HTTP triggered function having below code.

    Function code

    import logging
    import azure.functions as func
    import cv2
    
    
    def main(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')
        logging.info(f'OpenCV version: {cv2.__version__}')
    
        name = req.params.get('name')
        if not name:
            try:
                req_body = req.get_json()
            except ValueError:
                pass
            else:
                name = req_body.get('name')
    
        if name:
            return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
        else:
            return func.HttpResponse(
                 "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
                 status_code=200
            )
    
    

    requirements.txt

    azure-functions
    opencv-contrib-python==4.5.5.62
    

    I have debugged my function in vs code and able to get the expected output while executing the function locally.

    enter image description here

    Post publishing the function to function app, I am also getting successful output.

    enter image description here

    If requirement.txt file is containing all the modules post deployment then your function should work alike me. If the issue still persists, you can consider deploying the function to a freshly created function app.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search