当前位置:网站首页>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它将安装所有相关的依赖项并解决错误。
边栏推荐
- Webdypro layout control cannot be used_ SAP LIUMENG
- Nat. Commun. | Knowledge integration and decision support for accelerating the discovery of antibiotic resistance genes
- postman切换主题
- 几个对程序员的误解,害人不浅!
- 一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue
- Fiddler模拟低速网络环境
- Detailed derivation of perspective projection transformation and related applications
- 为 Chocolatey 设置代理
- AHK common functions
- 复利最高的保险产品是什么?一年要交多少钱?
猜你喜欢

Fiddler为测试做什么

SOA架构/测试阶段接口描述语言转换方案

Intelligent scenic spot video monitoring 5g intelligent light pole gateway networking integrated pole

Numpy learning notes

Postman parameterization

善用产业链招商,打造产业集群效应,实现产业协同发展

What is the 100th trillion digit of PI decimal point? Google gives the answer with Debian server

Mm main tables and main fields_ SAP LIUMENG_

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

MFC基础知识与课程设计思路
随机推荐
Postman common assertions
Fabric.js 元素被选中时保持原有层级
Nat. Commun. | Knowledge integration and decision support for accelerating the discovery of antibiotic resistance genes
[proteus simulation] ds18b20+ alarm temperature adjustable +lm016 display
Rethinking atlas revolution for semantic image segmentation (deeplobv3) personal summary
What is the highest compound interest insurance product? How much does it cost a year?
fail-fast和fail-safe
IDEA的Swing可视化插件JFormDesigner
MFC基础知识与课程设计思路
Fabric.js 激活输入框
SOA架构/测试阶段接口描述语言转换方案
Fiddler过滤会话
Fiddler set breakpoint
AIChE | ab initio drug design framework integrating mathematical programming method and deep learning model
CAP 6.1 版本发布通告
Cannot locate a 64-bit Oracle Client library:The specified module could not be found.
Detailed derivation of perspective projection transformation and related applications
【玩转华为云】鲲鹏DevKit迁移实战
Postman switching topics
Fabric.js 缩放画布