0

I am attempting to write a simple Azure Function app in Python.

My function app work fine in the local simulator but when I attempt to publish it to Azure, it fails with this error:

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.

My understanding is that the ZBar libraries cannot be found by the runtime environment (Lunix x64 for Azure Functions).

My "requirements.txt" file does not contain zbar but it does contain pyzbar which is the wrapper I am using.

My question is: how can I deploy the necessary libraries in the host in Azure functions?

Stephane
  • 3,173
  • 3
  • 29
  • 42
  • Try adding zbar=0.10 in your requirements.txt and redeploy your function app? Also, Validate if zbar library is present in venv in your local function folder? – SiddheshDesai Apr 06 '23 at 11:21
  • Attemting to add zbar to the requirements.txt file causes the deployment to fail. I'm not sure what you mean by your second suggestion: the zbar library is not deployed with my function. It's part of the Python deployment in windows but should be installed using apt-get on Linux – Stephane Apr 06 '23 at 11:34

1 Answers1

1

I tried adding pyzbar[zbar] in the requirements.txt of my Azure Function and deployed the function app in Azure Portal successfully like below:-

My requirements.txt

enter image description here

I used the below commands to deploy my function app to azure from local env:-

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

The remote build will include pyzbar package in the deployment

Output:-

enter image description here

pyzbar got installed successfully like below:-

enter image description here

Function got deployed in Azure Portal, Refer below:-

enter image description here

Portal:-

enter image description here

Function:-

enter image description here

As Zbar library cannot be installed with pip cause it has a dependency on the Zbar package that needs to be installed from here- https://zbar.sourceforge.net/download.html, You can create a custom function docker image and install your Zbar library like below :-

Custom docker image :-

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

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

Build your docker image:-

docker build -t <your_image_name> .

Update your function app to use the docker image by referencing it in Host.json like below:-

{
  "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

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11
  • Thank yo for the detailed answer. Unfortunately, using a custom dcker image for azure function requires a "premium" service level which is actually more expensive (and quite a lot too) thank running a full app service. I now realize I should have added that to my initial question. I will still accept your answer, though, since it seems it is the only one at this time. – Stephane Apr 17 '23 at 06:46