我试图运行cv2,但当我试图导入它时,我得到以下错误:

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

建议的在线解决方案是安装

apt install libgl1-mesa-glx

但这是已经安装的最新版本。

注:我实际上是在Docker上运行这个,我无法检查OpenCV版本。我尝试导入matplotlib,导入正常。


当前回答

在缺少各种图形库的非GUI服务器上使用pip3安装opencv后,在centos 8上出现了同样的问题。

DNF安装opencv

拉入所有需要的依赖项。

其他回答

把这个放到Dockerfile中

RUN apt-get update
RUN apt install -y libgl1-mesa-glx

排队前

COPY requirements.txt requirements.txt

例如

......

RUN apt-get update
RUN apt install -y libgl1-mesa-glx

COPY requirements.txt requirements.txt

......

下面是你需要的解决方案:

pip install -U opencv-python
apt update && apt install -y libsm6 libxext6 ffmpeg libfontconfig1 libxrender1 libgl1-mesa-glx

我在docker容器中使用cv2时遇到了这个问题。我通过:

pip install opencv-contrib-python

安装opencv-contrib-python而不是opencv-python。

在我看来,这是一个更好的解决方案。python3-opencv包包含OpenCV的所有系统依赖项。

RUN apt-get update && apt-get install -y python3-opencv
RUN pip install opencv-python

在缺少各种图形库的非GUI服务器上使用pip3安装opencv后,在centos 8上出现了同样的问题。

DNF安装opencv

拉入所有需要的依赖项。