Python "ImportError: libgthread-2.0.so.0: cannot open" in CI
A compiled package imported fine to pip but, at import time, needs the GLib threading runtime (libgthread-2.0.so.0) which is not installed on a minimal runner image.
What this error means
Importing a package such as opencv crashes with ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory. The wheel installed cleanly; only the system GLib library is missing.
Python traceback
ImportError: libgthread-2.0.so.0: cannot open shared object file:
No such file or directoryCommon causes
GLib runtime not installed
Slim/headless images omit GLib. Wheels that dynamically link libgthread/libglib import fine on a full image but fail here.
Heavier package variant than needed
A GUI-enabled variant (e.g. opencv-python) pulls in GLib at import; a headless variant avoids it.
How to fix it
Install the GLib runtime
Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y libglib2.0-0Use a headless variant where possible
Terminal
pip uninstall -y opencv-python
pip install opencv-python-headlessHow to prevent it
- Bake GLib (
libglib2.0-0) into images that import such wheels. - Prefer headless package variants in CI.
- Map each
.soin an ImportError to its system package and install it in the image.
Related guides
Python "ImportError: libSM.so.6: cannot open shared object file"Fix "ImportError: libSM.so.6 / libXext.so.6: cannot open shared object file" in CI - X11 client libraries a G…
Python "error: command 'gcc' failed with exit status 1" VariantsFix "error: command 'gcc' failed with exit status 1" building a C extension in CI - gcc ran but the compile i…
Self-Healing CI: Missing System Packages and Setup GapsA missing system library or tool fails the build until someone installs it. See the manual fix and how self-h…