docker中执行python报ImportError: libGL.so.1: cannot open shared object file: No such file or dir错误的解决方法

avatar
作者
筋斗云
阅读量:1

错误细节:

Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 181, in <module>     bootstrap()   File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 153, in bootstrap     native_module = importlib.import_module("cv2")   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module     return _bootstrap._gcd_import(name[level:], package, level) ImportError: libGL.so.1: cannot open shared object file: No such file or directory 

错误原因:所用的docker镜像中缺乏opencv所需依赖(libGL.so.1)

解决方法:通过安装 opencv-python的headless 版本,它会安装所有相关的依赖项,具体安装指令如下:

# 报错opencv安装指令 pip install opencv-python==4.8.0.68  # opencv-python-headless安装指令 pip install opencv-python-headless==4.8.0.68

参考博客:ImportError: libGL.so.1: cannot open shared object file: No such file or dir...解决Python import cv2报错-CSDN博客

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!