Azure Function App is not identifying the package getting ModuleNotFoundError: No module named 'fitz'

Veerendra 0 Reputation points
2024-09-27T06:41:43.66+00:00

Fitz package is installed while triggering in the Function App, But still getting error as below.

`2024-09-27T06:31:37Z [Error] Command failed with error: Traceback (most recent call last): File "/home/site/wwwroot/app/prepdocs.py", line 5, in

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

2 answers

Sort by: Most helpful
  1. Pinaki Ghatak 4,210 Reputation points Microsoft Employee
    2024-09-27T18:25:58.5733333+00:00

    Hello @Veerendra

    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:

    • The package can't be found * The package isn't resolved with proper Linux wheel
    • The package is incompatible with the Python interpreter version
    • The package conflicts with other packages
    • The package supports only Windows and macOS platforms To identify the actual cause of your issue, you need to get the Python project files that run on your function app.

    If you don't have the project files on your local computer, you can get them in one of the following ways:

    1. Download the file by copying and pasting the URL into your browser.
    2. Use the Azure Functions Core Tools to download the files. Once you have the project files, you can check if the 'fitz' package is included in the requirements.txt file. If it is not included, you can add it to the file and redeploy the function app. If the package is already included in the requirements.txt file, you can try updating the package to the latest version or reinstalling the package. You can also try checking if there are any other packages that conflict with the 'fitz' package. If none of the above solutions work, it is possible that the package is not compatible with the Python interpreter version or the Linux wheel is not resolved properly. In this case, you can try using a different version of the package or resolving the Linux wheel issue.

    I hope this helps you resolve the issue.

    0 comments No comments

  2. LeelaRajeshSayana-MSFT 15,071 Reputation points Microsoft Employee
    2024-09-27T22:43:11.7466667+00:00

    Hi @Veerendra Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    I have tried to test the fitz module in Azure Python function by opening a document and getting the page count of the PDF file using the module supported methods. I could do that without any issues by adding the `PyMuPDF in the requirements.txt file and pushing it to the function app.

    Here are the contents of my requirements.txt file

    azure-functions
    PyMuPDF
    

    Within the function app, I am accessing the fitz module with an import command and getting the file size as follows

    import azure.functions as func
    import logging
    import fitz
    
    app = func.FunctionApp()
    
    
    @app.blob_trigger(arg_name="myblob", path="pythonapp",
                                   connection="lsayanastoragesftp_STORAGE") 
    def fitz_blob_trigger(myblob: func.InputStream):
        logging.info(f"Python blob trigger function processed blob"
                    f"Name: {myblob.name}"
                    f"Blob Size: {myblob.length} bytes"
                    f"Blob URL : {myblob.uri}")
        doc = fitz.open("01March2024.pdf")
        logging.info(f"Pages count is  {doc.page_count}")
    
    
    

    I could see from the invocation logs that the Function app is able to utilize the module and process the data without any issues. Please refer the below image for reference

    User's image

    Hope this helps! Let me know if you need any additional assistance.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    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.