简体   繁体   English

Azure Functions:在Linux下的Python函数中,如何导入opencv/imutils等非标准模块?

[英]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

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:

requirements.txt要求.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.

相关问题 在Jython中导入非标准的python模块 - Import non-standard python module in Jython Python 3.6无法在Linux下安装到非标准目录 - Python 3.6 fails to install to non-standard directory under Linux 如何在非标准路径的Python 3.3安装中正确安装pip3? - How do I correctly install pip3 in a Python 3.3 installation located at a non-standard path? Python:当格式为非标准格式时,如何使for循环将数据附加到列表? - Python: How do I make a for loop append data to a list when the format is non-standard? 如何在Python中编码/解码此BeautifulSoup字符串,以便输出非标准拉丁字符? - How do I encode/decode this BeautifulSoup string in Python so that non-standard Latin characters are output? 如何使用SOAPpy创建非标准类型? - How do I create a non-standard type with SOAPpy? 如何将一列非标准字符串更改为日期时间? - How do I change a column of non-standard strings to datetime? 3、Mac 上导入 imutils 错误 - Opencv, Tkinter, Python 3, import imutils error on Mac 如何指定非标准的Python解释器? - How to specify non-standard Python interpreter? Linux / Python如何将root访问py模块作为非r​​oot用户导入? - Linux/Python How do I import a root access py module as a non-root user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM