python - 如何在 python Azure 函数中使用 ZBar 库?

标签 python azure azure-functions

我正在尝试用 Python 编写一个简单的 Azure Function 应用程序。

我的函数应用程序在本地模拟器中工作正常,但当我尝试将其发布到 Azure 时,它​​失败并出现以下错误:

Exception while executing function: Functions.ProcessPDF Result: Failure
Exception: ImportError: Unable to find zbar shared library. Please check the requirements.txt file for the missing module.

我的理解是运行时环境(Lunix x64 for Azure Functions)无法找到 ZBar 库。

我的“requirements.txt”文件不包含 zbar,但它包含 pyzbar,这是我正在使用的包装器。

我的问题是:如何在 Azure 函数的主机中部署必要的库?

最佳答案

我尝试在 Azure Function 的requirements.txt 中添加 pyzbar[zbar] 并在 Azure 门户中成功部署函数应用,如下所示:-

我的要求.txt

enter image description here

我使用以下命令将我的函数应用程序从本地环境部署到 azure:-

func azure functionapp publish <function-app-name> 
func azure functionapp publish <app_name> --build remote

远程构建将在部署中包含 pyzbar 包

输出:-

enter image description here

pyzbar 已成功安装,如下所示:-

enter image description here

功能已部署在Azure Portal中,请参阅以下内容:-

enter image description here

门户:-

enter image description here

功能:-

enter image description here

由于 Zbar 库无法通过 pip 安装,因为它依赖于需要从此处安装的 Zbar 软件包 - https://zbar.sourceforge.net/download.html ,您可以创建自定义功能 docker 镜像并安装 Zbar 库,如下所示 :-

自定义 Docker 镜像:-

FROM mcr.microsoft.com/azure-functions/python:3.0

# Install zbar libraries
RUN apt-get update \
    && apt-get install -y libzbar0

构建你的 Docker 镜像:-

docker build -t <your_image_name> .

通过在 Host.json 中引用 Docker 镜像来更新您的函数应用,如下所示:-

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "functions": [
    {
      "name": "MyFunction",
      "docker": {
        "image": "<your_image_name>"
      }
    }
  ]
}

References:-

Refer the post's below for more insights:-

python - ImportError: Unable to find zbar shared library on Flask - Stack Overflow By Mise Javier Buzzi stefan Kautuk Dwivedi

Add support to load library externally · Issue #40 · NaturalHistoryMuseum/pyzbar · GitHub By nickovs

关于python - 如何在 python Azure 函数中使用 ZBar 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75948875/

相关文章:

c++ - 是否可以拆分 SWIG 模块进行编译,但在链接时重新加入它?

azure - 如何将 TensorFlow Serving 作为 Azure 容器实例运行并传递 docker 命令

azure - 使用 Azure Function 删除 CosmosDB 条目

azure - Visual Studio Code 无法部署到 azure - 凭据参数需要实现signREQUEST

.net - C#/.NET : How do I create a DNS record in an Azure DNS zone using the new ARM SDK?

具有 Azure AD 访问 token 的 Azure Function

python - Django 中 ManyToMany 关系的内联编辑

python - 在Tkinter中嵌入Matplotlib,显示问题

python - 为什么 json.loads 关心使用哪种类型的引号?

Azure AD SSO Multi-Tenancy 应用程序/AD FS 声明提供程序问题