我们正在使用Azure CLI部署基于Python的Azure函数,但是在导入cv2库时出现以下错误。
ImportError:libgthread-2.0.so.0:无法打开共享对象文件:没有这样的文件或目录
我们没有使用任何docker映像。宁愿使用非基于docker的解决方案。
Exception: ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
Stack: File "/usr/local/lib/python3.6/site-packages/azure_functions_worker/dispatcher.py", line 239, in _handle__function_load_request
func_request.metadata.entry_point)
File "/usr/local/lib/python3.6/site-packages/azure_functions_worker/loader.py", line 66, in load_function
mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/FaceFinderHttpTrigger/__init__.py", line 11, in <module>
import cv2
File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
答案 0 :(得分:0)
有一个类似的SO线程Azure Functions: In a Python function under Linux, how do I import a non-standard module such as opencv/imutils?,与您的问题相同。
由于libgthread
共享库是Linux基础库,根据我的经验,这似乎是由于Azure CLI无法将这些具有本地依赖项的Python软件包打包为Azure Function引起的。因此,我认为唯一的解决方案是按照官方文档Create a function on Linux using a custom image
所述,自行将Azure Function作为Docker容器构建,或尝试将Azure CLI命令func azure functionapp publish
与--build-native-deps
选项一起使用使用Docker容器构建和配置依赖项。
据我所知,有一个博客OPENCV WITH AZURE FUNCTIONS
似乎可以与opencv一起用于Azure Functions,但据我看来,它仅在本地开发环境上运行,而不是在云上运行。因此,我仍然建议您使用本机依赖项将应用程序部署为该应用程序的Docker contaier。