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

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

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

apt install libgl1-mesa-glx

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

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


当前回答

如果你使用CentOS、RHEL、Fedora或其他使用yum的linux发行版,你将需要:

sudo yum install mesa-libGL -y

其他回答

把这个放到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

......

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

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

在rocky linux 9中,我使用命令解决了这个错误 安装mesa-libGLU

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

pip install opencv-contrib-python

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

对于树莓派来说,这样写,为我工作:

sudo apt-get install ffmpeg libsm6 libxext6  -y