Azure Functions: In a Python function under Linux, how do I import a non-standard module such as opencv/imutils?

我怕爱的太早我们不能终老 提交于 2019-12-23 05:04:43

问题


I am trying to export my computer vision API, which is functioning correctly under macOS, to an Azure Function.

I tried to use the docker approach:

func azure functionapp publish --build-native-deps

but I keep getting the error:

can't import cv2 and imutils

log file

and

Exception: ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory

Here is the requirements.txt:

requirements.txt

How do I solve this problem? Or must I switch to AWS Lambda?

I have access to Kudu if that's helpful.

Thanks in advance!


回答1:


I think the issue is lack of the necessary library libgthread. To fix it, you need to add it into your Docker file to build your own image for your function deployment.

On Azure, please follow the section Build the image from the Docker file of the offical document Create a function on Linux using a custom image to add the code below in azure-functions/python:2.0 Docker file.

RUN apt-get update && \
    apt-get install -y libglib2.0-dev

But it will add a new docker image layer, so you can add libglib2.0-dev into azure-functions/base:2.0 like below.

# Line 19
RUN apt-get update && \
    apt-get install -y gnupg wget unzip libglib2.0-dev && \
    wget https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.0.0/Microsoft.Azure.Functions.ExtensionBundle.1.0.0.zip && \
    mkdir -p /FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.0.0 && \
    unzip /Microsoft.Azure.Functions.ExtensionBundle.1.0.0.zip -d /FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.0.0 && \
    rm -f /Microsoft.Azure.Functions.ExtensionBundle.1.0.0.zip


来源:https://stackoverflow.com/questions/56015616/azure-functions-in-a-python-function-under-linux-how-do-i-import-a-non-standar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!