Azure function gives Exception: ModuleNotFoundError: No module named 'XXXXXXXX'. Cannot find module.

Aditya Patil 20 Reputation points
2024-03-24T06:55:06.95+00:00

AZURE FUNCTIONS -
Operating System: Linux

Runtime version: 4.31.1.1

I am using Azure Functions with Python, which have been working as expected so far. However, all the recent Azure Functions that I have built and deployed are giving module not found error (works locally on windows system) on the imported python modules even though they have been included in the requirements.txt file. I can clearly see that the modules get installed in GitHub build and deployment, but the Azure Function log stream shows

"Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: ModuleNotFoundError: No module named 'pandas'. Cannot find module. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: 

I have been investigating this issue for a few days now. I went through the documentation for troubleshooting and previous GitHub threads discussing this or other similar issues. At first the issue seemed to be only with "pyodbc" module but on further investigation I found that it is an error on Azure side and not on Python. Similar kind of issues were found before where Azure Functions failed with Python and they were swiftly resolved in later versions.

I have tried:

  1. Rebuilding and redeploying the functions
  2. Using alternative modules
  3. Downgrading the python modules to previous stable versions (as suggested in some of the solutions)

but to no avail.

I would really appreciate if someone could give me some inputs.

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

Accepted answer
  1. MayankBargali-MSFT 70,731 Reputation points
    2024-04-04T07:45:53.35+00:00

    @Aditya Patil I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution in case you'd like to "Accept" the answer.

    Issue:

    You observed the below error on your function app log streams:

    "Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
    Exception: ModuleNotFoundError: No module named 'pandas'. Cannot find module. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: 
    
    

    Solution:

    You tried remote build and deployment to deploy your function app and confirm that your function app was working as expected.

    Thank you again for your time and patience throughout this issue.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Deepanshukatara-6769 11,625 Reputation points
    2024-03-24T08:40:01.94+00:00

    Hi Aditya,

    Thanks for reaching here! If understood right you have deployed Python function app and facing module-related errors. These errors typically result in the following Azure Functions error message:

    "Exception: ModuleNotFoundError: No module named 'module_name'."

    This error occurs when a Python function app fails to load a Python module. The root cause for this error is one of the following issues:

    Please let us know if further query or issue remains.

    kindly accept answer if it has helped , Thanks!


  2. Aditya Patil 20 Reputation points
    2024-03-27T11:55:22.35+00:00

    Hey guys,

    I tried remote build and deployment, and it worked, for some reason it is not working through our CI/CD pipeline. Anyways thank you so much, I truly appreciate your support.

    0 comments No comments

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.