我试图运行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,导入正常。
当前回答
安装opencv-python-headless而不是opencv-python 这对我来说很管用! 我正在将我的网站部署到Azure上,然后弹出这个异常: ImportError: libGL.so。1:无法打开共享对象文件:没有共享对象文件或目录 然后卸载opencv-python包,安装后者, 冻结需求,然后再次部署, 这样问题就解决了。
其他回答
对我来说,这个问题与代理设置有关。对于pypi,我使用nexus镜像到pypi,对于opencv什么都不工作。直到我连接到另一个网络。
对我来说,唯一有效的WA是:
# These are for libGL.so issues
# RUN apt-get update
# RUN apt install libgl1-mesa-glx
# RUN apt-get install -y python3-opencv
# RUN pip3 install opencv-python
RUN pip3 install opencv-python-headless==4.5.3.56
在Dockerfile中添加以下代码行:
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
这些命令安装了cv2依赖项,这些依赖项通常存在于本地机器上,但可能在Docker容器中缺失而导致问题。
[2022年1月20日的小更新:Docker建议,永远不要单独放置RUN apt-get更新,导致缓存问题]
在我的情况下,做以下就足够了,与上面的解决方案相比,这也节省了空间
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
......