0

I have exactly the same question asked here some time ago.

I tried the recommended solutions: pip install azure

But no luck!

This is the code I'm following in the basic tutorial here:

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
        )

I keep getting the same error:

ModuleNotFoundError: No module named 'azure.functions'

Can anyone help?

unstuck
  • 563
  • 2
  • 12
  • 29

1 Answers1

1

After reproducing from my end, this was working fine. Make sure you are performing Azure functions inside a virtual environment.

A virtual environment is automatically created when we select a python interpreter while creating the Azure functions.

enter image description here

Alternatively, you can refer below commands to create a virtual environment.

Description Command
Install Virtual Environment pip3 install virtualenv
Create Virtual Environment Python3 -m venv .venv
Activate Virtual Environment .venv\Scripts\Activate.ps1

After creating a virtual environment then try installing azure functions using pip

pip install azure-functions

Also, make sure that the installed packages have been included in the requirements.txt file

pip freeze > requirements.txt

enter image description here

RESULTS:

enter image description here

REFERENCES: Troubleshoot ModuleNotFoundError

SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18
  • Thank you, pip install azure-functions solved the problem, now I'm stuck on nothing happening upon running __init__.py so I'll open another question. – unstuck Aug 26 '22 at 15:41