[英]Azure Functions: In a Python function under Linux, how do I import a non-standard module such as opencv/imutils?
I am trying to export my computer vision API, which is functioning correctly under macOS, to an Azure Function.我正在尝试将在 macOS 下正常运行的计算机视觉 API 导出到 Azure 函数。
I tried to use the docker approach:我尝试使用 docker 方法:
func azure functionapp publish --build-native-deps
but I keep getting the error:但我不断收到错误消息:
can't import cv2 and imutils
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?
还是我必须切换到 AWS Lambda?
I have access to Kudu if that's helpful.如果有帮助,我可以访问 Kudu。
Thanks in advance!提前致谢!
The Azure team has updated the default function image to include libglib2.0-dev Azure 团队已更新默认函数映像以包含 libglib2.0-dev
You will need to install the headless version of OpenCV through pip instead of the default.您需要通过 pip 而不是默认安装 OpenCV 的 headless 版本。
https://pypi.org/project/opencv-python-headless/ https://pypi.org/project/opencv-python-headless/
I think the issue is lack of the necessary library libgthread
.我认为问题在于缺少必要的库
libgthread
。 To fix it, you need to add it into your Docker file to build your own image for your function deployment.要修复它,您需要将它添加到您的 Docker 文件中,以便为您的函数部署构建您自己的映像。
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.在 Azure 上,请按照官方文档
Create a function on Linux using a custom image
Build the image from the Docker file
部分在azure-functions/python:2.0
Docker 文件中添加以下代码。
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.但它会添加一个新的
libglib2.0-dev
镜像层,因此您可以将libglib2.0-dev
添加到azure-functions/base:2.0
如下所示。
# 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.