【解决方法】libGL.so.1: cannot open shared object file: No such file or directory-CSDN博客
在配云端GPU服务器时,出现这个错误
File "/usr/local/lib/python3.6/dist-packages/cv2/__init__.py", line 8, in <module>
from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
解决方法(easy)
setup 에서 cv2 설치 오류가 발생합니다. · Issue #78 · Korea-Health-Datathon/KHD2020 · GitHub
卸载 pip uninstall opencv-python
安装 pip install opencv-python-headless
在Stack Overflow上有其他回答
Ubuntu系统
在docker中出错
将以下行添加到您的 Dockerfile:
# ubuntu系统
RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6 -y
这些命令安装通常存在于本地计算机上的 cv2 依赖项,但可能会在您的 Docker 容器中丢失,从而导致问题。
libGL.so.1由 package 提供libgl1,所以添加一下代码
apt-get update && apt-get install libgl1
还有一些解决方案,例如
环境是ubuntu16.04。指令:
apt update
apt install libgl1-mesa-glx
这里说明了这个包的作用个,然后说了是Ubuntu16.0
FROM ubuntu:16.04
# 安装libgl库
RUN apt-get update && apt-get install -y libgl1-mesa-glx
# 安装其他必要的软件
RUN apt-get install -y software-properties-common && add-apt-repository ppa:jonathonf/python-3.6 && apt-get update && apt-get install -y python3.6 python3-setuptools python3-pip
# 设置Python3.6为默认版本
RUN ln -sf /usr/bin/python3.6 /usr/bin/python3 && ln -sf /usr/bin/python3 /usr/bin/python
# 安装其他必要的Python库
RUN pip3 install --no-cache-dir numpy opencv-python
CentOS系统
如果您使用的是 CentOS、RHEL、Fedora 或其他使用 的 linux 发行版yum,您将需要:
sudo yum install mesa-libGL -y
注意,这个安装包名和linux系统需要对应。否则,No package libgl1 available.
当前yum源找不到所需包,安装epel源即可
yum install -y epel-release
最终放在Dockerfile里是这样解决的,
USER root
RUN yum install -y mesa-libGL
RUN yum install -y mesa-libGL-devel # 安装这个最终解决