1

I have an azure function python app deployed which makes use of multiple python files from the codebase. Currently the structure is as follows :

├── HttpExample
│   ├── __init__.py
│   └── function.json
├── getting_started.md
├── host.json
├── local.settings.json
├── requirements.txt
└── shared_code
    ├── __init__.py
    ├── prep_backup.py
    ├── final_execution.py
    ├── final_helper.py
    ├── file_info.py
    └── requirements.txt

In my HttpExample, inside the init.py, I call my function to do the work as follows:

import logging

import azure.functions as func
from shared_code import final_execution

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    final_execution.run_function() # fails here

    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
        )

But the final_execution makes use of import statements pointing to

from prep_backup import func1,func2

But the above block fails as :

Result: Failure Exception: ModuleNotFoundError: No module named 'prep_backup'. Please check the requirements.txt file for the missing module. 

All the necessary public packages used are listed in the requeirement.txt.

Any suggestions to work around this?

RCB
  • 479
  • 1
  • 9

1 Answers1

0

Since your prep_backup.py is within the same folder(shared_code) as the caller module(final_execution.py), you can try importing the function like this instead(put a '.' in front of the module name). This is true for Python 3 onwards.

from .prep_backup import func1,func2

This has been mentioned in the existing SO question.

Anupam Chand
  • 2,209
  • 1
  • 5
  • 14