使用 Python 的 Azure 函数应用程序出现“ModuleNotFoundError”

gra*_*019 4 python azure python-import azure-function-app

我不断收到错误消息

ModuleNotFoundError:没有名为“azure”的模块

对于第 4 行,下面是使用本教程import azure.functions as func 设计的初始化文件的代码

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
        )
Run Code Online (Sandbox Code Playgroud)

对此的任何帮助将不胜感激!

MDa*_*Dah 8

您是否在 python 环境中 pip 安装了该库?

pip install [client library]
Run Code Online (Sandbox Code Playgroud)

客户端库可以在这里找到

  • 我遇到了上述命令的问题。可能是版本不匹配造成的。pip install azure-functions 对我有用。 (5认同)