TraceResolve

OpenCV: ImportError: libGL.so.1 cannot open shared object file

>>> import cv2 ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Immediate Remediation
bash
sudo apt-get update && sudo apt-get install -y libgl1 libglib2.0-0
Root Cause Analysis

OpenCV dynamically links against the system OpenGL library (libGL.so.1) for GUI/highgui features; minimal Docker images and headless servers often omit this system package, causing imports of cv2 to fail.

Verification & Guardrails

  • For headless servers, replace your `opencv-python` package with `opencv-python-headless`.
  • On RHEL/CentOS run `sudo yum install mesa-libGL`; on Alpine Linux use `apk add libgl`.
  • After installing, restart your Python process to verify the import works.

Have a custom or uncategorized crash?

Run your trace through our in-memory client privacy sandbox for instant SRE remediation.

Open Diagnostic Studio