Skip to content
Latchkey

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 directory

Common 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-0

Use a headless variant where possible

Terminal
pip uninstall -y opencv-python
pip install opencv-python-headless

How to prevent it

  • Bake GLib (libglib2.0-0) into images that import such wheels.
  • Prefer headless package variants in CI.
  • Map each .so in an ImportError to its system package and install it in the image.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →