我试图运行cv2,但当我试图导入它时,我得到以下错误:
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
建议的在线解决方案是安装
apt install libgl1-mesa-glx
但这是已经安装的最新版本。
注:我实际上是在Docker上运行这个,我无法检查OpenCV版本。我尝试导入matplotlib,导入正常。
我试图运行cv2,但当我试图导入它时,我得到以下错误:
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
建议的在线解决方案是安装
apt install libgl1-mesa-glx
但这是已经安装的最新版本。
注:我实际上是在Docker上运行这个,我无法检查OpenCV版本。我尝试导入matplotlib,导入正常。
当前回答
在我看来,这是一个更好的解决方案。python3-opencv包包含OpenCV的所有系统依赖项。
RUN apt-get update && apt-get install -y python3-opencv
RUN pip install opencv-python
其他回答
在rocky linux 9中,我使用命令解决了这个错误 安装mesa-libGLU
在缺少各种图形库的非GUI服务器上使用pip3安装opencv后,在centos 8上出现了同样的问题。
DNF安装opencv
拉入所有需要的依赖项。
当我试图在GCP Appengine Flex服务器环境中使用OpenCV时,我得到了同样的错误。将requirements.txt中的“opencv-python”替换为“opencv-python-headless”解决了这个问题。
OpenCV文档讨论了桌面和服务器(无头)环境的不同包。
在我的情况下,做以下就足够了,与上面的解决方案相比,这也节省了空间
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
把这个放到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
......