当前位置:网站首页>Importerror: libgl.so.1: cannot open shared object file: no such file or directory
Importerror: libgl.so.1: cannot open shared object file: no such file or directory
2022-06-10 16:17:00 【点PY】
导入错误:libgl.so.1:无法打开共享对象文件:没有这样的文件或目录
如果您的应用程序依赖于cv2或opencv-python如果您尝试使用诸如 python:3.9-slim、python:buster 等图像构建 docker 容器,并且如果您导入 cv2,您将收到以下错误。
docker run -it python:3.9-slim bash -c "pip -q install opencv-python; python -c 'import cv2'"
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/cv2/__init__.py", line 5, in <module>
from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
S1:安装cv2依赖
cv2解决此问题的更简单方法是您可以更新软件包并安装正常运行所需的其他依赖项。
这些依赖项将主要存在于您的本地计算机中,因此当您使用基于 python 的图像执行 docker 构建时,应用程序运行没有任何问题,您将收到此错误。
只需将以下几行添加到您的行DockerFile中即可解决此问题。这将确保更新软件包并安装运行所需的其他软件包cv2。
RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6 -y
S2: 安装opencv-python-headless
代替opencv-python,您可以安装opencv-python-headless包含没有外部依赖项的预编译二进制轮(除了numpy),并且适用于 Docker 等无头环境。
与此相比,python3-opencv这是一个更轻量级的包,并将 docker 映像大小减少了 700MB。
RUN apt-get update && apt-get install -y opencv-python-headless
RUN pip install opencv-python-headless
S3: 仅安装依赖项 (libgl1)
以上所有解决方案都将安装cv2依赖项,从而增加图像大小。
如果您不想增加图像大小,则可以通过安装 libgl1 依赖项来解决问题,如下所示。这不是推荐的解决方案,但如果您只是获得Importerror: libgl.so.1
apt-get update && apt-get install libgl1
结论
importerror: libgl.so.1 : cannot open shared object file: no such file or directory 主要是因为使用Docker构建应用时缺少cv2的依赖。这些依赖项将存在于本地实例中,因此您不会收到此错误。
我们可以通过安装所需的附加依赖项来解决此错误,cv2或者我们可以只使用其中一个包,例如python3-opencv,opencv-python-headless它将安装所有相关的依赖项并解决错误。
边栏推荐
- 防洪排涝监控 防洪排涝自动监测遥测终端
- ahk函数命令大全
- Fabric. JS centered element
- AIChE | 集成数学规划方法和深度学习模型的从头药物设计框架
- Fabric. JS zoom canvas
- AIChE | ab initio drug design framework integrating mathematical programming method and deep learning model
- Webdypro layout control cannot be used_ SAP LIUMENG
- How to own your own blog website from scratch [Huawei cloud to jianzhiyuan]
- 品牌难立,IPO难行,中国茶企困于“传统”?
- 线程面试相关问题
猜你喜欢
Example analysis of SQL injection error reporting

运筹说 第64期丨动态规划奠基人——理查德·贝尔曼

Xinsi technology helps Israel visuality systems promote the "left shift" of security

Pictographic dynamic graphic ideographic data

接口测试学习笔记

Carry forward the past and forge ahead into the future, multiple residuals | densenet (II)

Carry forward the past and forge ahead into the future, multiple residuals | densenet (I)

隐形马尔可夫模型及其训练(一)

Postman common assertions

Rethinking atlas revolution for semantic image segmentation (deeplobv3) personal summary
随机推荐
如何用Pygame制作简单的贪吃蛇游戏
MFC basic knowledge and course design ideas
Rethinking atlas revolution for semantic image segmentation (deeplobv3) personal summary
Fabric. JS lock the background image, not affected by zooming and dragging
Richard Behrman, the founder of dynamic planning
HTML+PHP+Mysql登录注册页面
Docker安装Redis镜像详细步骤(简单易懂,适合新手快速上手)
What is the 100th trillion digit of PI decimal point? Google gives the answer with Debian server
script 标签自带的属性
sql注入报错之注入原理实例解析
adb不是内部或外部命令,也不是可运行的程序或批处理文件
CAP 6.1 版本发布通告
Postman parameterization
Webdypro layout control cannot be used_ SAP LIUMENG
善用产业链招商,打造产业集群效应,实现产业协同发展
隐形马尔可夫模型及其训练(一)
Desai wisdom number - words (text wall): 25 kinds of popular toys for the post-80s children
Fabric. JSON for JS compact output
解决idea打开某个项目卡住的问题
Xinsi technology performed well in the Gartner application security test key capability report 2022 and won the highest score among the five common use cases