[英]Azure Functions: In a Python function under Linux, how do I import a non-standard module such as opencv/imutils?
我正在嘗試將在 macOS 下正常運行的計算機視覺 API 導出到 Azure 函數。
我嘗試使用 docker 方法:
func azure functionapp publish --build-native-deps
但我不斷收到錯誤消息:
can't import cv2 and imutils
和
Exception: ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
這是requirements.txt:
我該如何解決這個問題? 還是我必須切換到 AWS Lambda?
如果有幫助,我可以訪問 Kudu。
提前致謝!
Azure 團隊已更新默認函數映像以包含 libglib2.0-dev
您需要通過 pip 而不是默認安裝 OpenCV 的 headless 版本。
我認為問題在於缺少必要的庫libgthread
。 要修復它,您需要將它添加到您的 Docker 文件中,以便為您的函數部署構建您自己的映像。
在 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
但它會添加一個新的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.