首页 > 解决方案 > 在 Azure 函数中安装包时出错 (Visual Studio)

问题描述

我正在尝试在 azure 函数中安装包 tldextract,但无法安装。该包存在于 azure 函数文档中提供的 python 索引中,但仍无法导入。

帮助我在 Azure 函数中安装包。在此处输入图像描述

标签: pythonvisual-studioazurepackageazure-functions

解决方案


请确保将tldextract模块包含在 requirements.txt 文件中,该文件位于项目目录的根目录中。

要求.txt

然后将其导入您的代码中:

import tldextract

这是我的示例函数:

import logging, tldextract
import azure.functions as func

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

    domain = tldextract.extract("https://www.goodreads.com/").domain

    if domain:
        return func.HttpResponse(f"This HTTP triggered function executed successfully. Domain is: {domain}")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully.",
             status_code=200
        )

推荐阅读