问题
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