4

I keep getting the error

ModuleNotFoundError: No module named 'azure'

for line 4 where I import azure.functions as func Below is the code for my init file that has been designed using this tutorial

import logging
import azure.functions as func

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

    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"Hellod {name}!")

    else:
        return func.HttpResponse(
             "Please pass a name on the query string or in the request body",
             status_code=400
        )

Any help with this would be much appriciated!

3 Answers 3

8

Did you pip installed the library in your python environment?

pip install [client library]

The client libraries can be found here

Sign up to request clarification or add additional context in comments.

2 Comments

I was facing issues with above command. Might be due to version mismatch. pip install azure-functions worked for me.
Error: Starting with v5.0.0, the 'azure' meta-package is deprecated and cannot be installed anymore. Please install the service specific packages prefixed by azure needed for your application.
1

In ./myFunction/__init.py I have import helpers as h. I was getting this error. This was consistantly not working. After trying many things, the fix was doing 2 things:

  1. running npm install -g azure-functions-core-tools@3 to upgrade to the latest.
  2. clicking yes to a popup in VS Code that said something like "this Azure Function was not initialised in VS Code. Would you like it optimised?"

I'm not sure exactly which of these fixed it.

My folder structure is so (only including the relevant files):

.
├── requirements.txt
├── helpers.py
├── myFunction
│   ├── __init.py
│   └── function.json

1 Comment

Clicking "yes" on the popup in VS Code fixed it for me.
0

I had a similar problem when trying to use the azure-functions module in my Azure function written in Python. The solution I found was to install the azure-functions-core-tools package on my Mac OS X using the command brew install azure-functions-core-tools. This package contains the necessary tools to develop and test Azure functions locally. Mackbook Pro M3 Procesor brew install azure-functions-core-tools

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.