Streamlit Cloud apt deps failing + OpenCV import errors (libGL / libgthread)

1. Public app link:
https://face-stimuli-generator.streamlit.app

2. Public GitHub repo link (with requirements):
https://github.com/omertzuk/vmmr_face_stimuli_maker

3. Full error message:

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

and later after adjusting apt packages:

ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory

Apt dependency installation failure from logs (relevant excerpt)

The following packages have unmet dependencies:
libglib2.0-0 : Depends: libffi7 (>= 3.3~20180313) but it is not installable
Depends: libpcre3 but it is not installable
Recommends: libglib2.0-data but it is not going to be installed
Recommends: shared-mime-info but it is not going to be installed
Recommends: xdg-user-dirs but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
E: The following information from --solver 3.0 may provide additional context:
Unable to satisfy dependencies. Reached two conflicting decisions:

  1. libglib2.0-0:amd64=2.66.8-1+deb11u8 is selected for install
  2. libglib2.0-0:amd64 Depends libffi7 (>= 3.3~20180313)
    but none of the choices are installable:
    [no choices]

4. Streamlit + Python versions:

  • Streamlit 1.58.0

  • Python 3.14.5 (from Cloud logs)

Extra context:

  • App entrypoint: stimulus_generation\gui\app.py

  • Using opencv-python-headless in requirements.

  • Attempted packages.txt with libgl1 and libgles2, but adding libglib2.0-0 fails due to missing libffi7/libpcre3 on the base image.

Welcome to the Streamlit community and thanks for the detailed info! :tada: You’re running into a common deployment issue: ImportError for libGL.so.1 and libgthread-2.0.so.0, and apt dependency failures for libglib2.0-0 due to missing libffi7 and libpcre3. This is because Streamlit Community Cloud uses Debian Bullseye, which doesn’t provide libffi7 or libpcre3 anymore, so installing libglib2.0-0 fails and breaks your dependency chain. This is a known limitation of the current Community Cloud base image and not something you can fix from your end by tweaking packages.txt alone.

The best-practice workaround is to only include libgl1 (and possibly libgles2) in your packages.txt, and avoid adding libglib2.0-0, as it will always fail due to the missing dependencies in the current environment. For OpenCV, ensure you use opencv-python-headless in requirements.txt and only libgl1 in packages.txt. If another library (like imageai or mediapipe) is forcing opencv-python (non-headless) or libglib2.0-0, you may need to pin versions or remove those dependencies if possible. For more, see the official Streamlit docs on apt dependencies and community troubleshooting.

If you share a minimal reproducible example or your requirements.txt and packages.txt, the community can help debug further! And if you find a dependency that absolutely requires libglib2.0-0, you may need to consider self-hosting or Docker deployment, as Community Cloud’s base image can’t satisfy that dependency right now.

Sources:

Thanks for the detailed explanation.

Here is my current requirements.txt:

numpy
scipy
opencv-python-headless
scikit-image
pillow
matplotlib
pandas
pyyaml
tqdm
mediapipe
streamlit

# Optional heavy fallback detector — comment out if not needed
# face-alignment
# torch
# torchvision

And my current packages.txt:

libgl1
libgles2
libglib2.0-0

Based on your explanation, I understand that I should remove libglib2.0-0 from packages.txt, and probably keep only:

libgl1

or possibly remove packages.txt entirely if opencv-python-headless is sufficient.

One additional thing I would like to clarify: my requirements include mediapipe. Could mediapipe be pulling in a non-headless OpenCV dependency, or otherwise causing the missing libGL.so.1 / libgthread-2.0.so.0 issue, even though I explicitly list opencv-python-headless?

The app imports the processing pipeline when Streamlit starts, before the user presses “Run”. That pipeline uses OpenCV and MediaPipe for landmark detection. So I wonder whether the best solution for Streamlit Cloud is:

  1. Remove libglib2.0-0 from packages.txt.

  2. Keep only opencv-python-headless in the cloud environment.

  3. Remove mediapipe from the cloud requirements.txt.

  4. Make the heavy image-processing imports lazy, so the Streamlit UI can load first.

  5. Use uploaded/precomputed landmark JSON files on Streamlit Cloud, and keep automatic MediaPipe landmark detection only for local/lab use.

Does that sound like the right direction for Streamlit Community Cloud, or is there a safe way to keep mediapipe installed together with opencv-python-headless without triggering these system library issues?