Deployment Error: ImportError: libGL.so.1 persists despite packages.txt on Streamlit Cloud

Hi Streamlit Community,

I’m trying to deploy a Streamlit app from GitHub that uses OpenCV for computer vision tasks. The app runs successfully locally in my Python 3.10 Conda environment.

However, I’m consistently facing a deployment error on Streamlit Cloud that prevents the app from starting. The error occurs during the import of cv2.

The Error Message:

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

This traceback points to the import of cv2 within my utils/analysis.py or other places where cv2 is used.

Relevant Files and Configuration:

My project structure includes a .streamlit folder at the root of the repository containing configuration files:

  1. requirements.txt : Lists the Python dependencies. I’ve ensured that only opencv-python-headless is included among the OpenCV variants, as recommended for headless environments.
# requirements.txt (snippet)
streamlit
...
opencv-python-headless
...
inference
supervision
...
  1. .streamlit/packages.txt : Intended to install necessary system libraries for OpenCV and other potential dependencies.
# .streamlit/packages.txt
libgl1
libsm6
libxrender1
libfontconfig1
libice6
pkg-config
ffmpeg
  1. .streamlit/config.toml : Configures the Streamlit environment.
# .streamlit/config.toml
[theme]
# ... theme settings ...

[server]
enableXsrfProtection = false
"folderWatch 黑名单" = ["/home/adminuser/venv/"] # Added to try and fix inotify errors

[runner]
python_version = "3.10" # To match my local environment

These files are correctly located in the .streamlit folder at the root of my public GitHub repository.

Troubleshooting Steps Taken:

I have taken the following steps based on common advice for libGL errors and dependency issues on Streamlit Cloud:

  1. Initially encountered the libGL.so.1 error and added libgl1 to .streamlit/packages.txt.

  2. Encountered an av build error (pkg-config is required) and added pkg-config and ffmpeg to .streamlit/packages.txt.

  3. Addressed previous configuration warnings by ensuring python_version is under [runner] and enableXsrfProtection is under [server] in config.toml, and fixed the TOML syntax error by quoting “folderWatch 黑名单”.

  4. Ensured requirements.txt only lists opencv-python-headless.

  5. Successfully committed and pushed all these changes to the main branch of my GitHub repository.

  6. Deleted the app on Streamlit Cloud and re-deployed it as a new app multiple times to ensure fresh builds and config loading.

Observation from Latest Deployment Logs:

My latest deployment logs show:

  • Streamlit Cloud is now using Python 3.10.17 for the dependency installation phase, confirming the config.toml python_version setting is being applied.

  • Python dependencies from requirements.txt (including av and `opencv-python- system libs?

My Hypothesis:

Based on the logs, it appears Streamlit Cloud is successfully cloning the repository, reading requirements.txt and parts of config.toml (like the Python version), but it is not reading or executing the instructions in .streamlit/packages.txt to install the necessary system libraries like libgl1, pkg-config, and ffmpeg. These missing system libraries are needed by opencv-python-headless (and av) at runtime, causing the ImportError.

Request for Help:

Could someone please help me understand why .streamlit/packages.txt might not be processed during the deployment build? Have I missed any configuration steps, or could there be an issue on the Streamlit Cloud platform preventing these system packages from being installed?

Here is the link to my GitHub repository:

Here is the URL of the deployed app (currently failing):
`https://guardian-ai.streamlit.

Looking at the deployment logs, I can see:

  • Python 3.10.17 is being used for dependency installation, which is correct based on my config.toml.

  • Python dependencies from requirements.txt are installed successfully by uv (including opencv-python-headless, av, inference-sdk, etc.).

  • However, the logs do not show any output indicating that system packages from .streamlit/packages.txt were installed before the Python dependencies. There are no apt-get or similar commands visible related to the packages listed in packages.txt.

This leads me to believe that Streamlit Cloud is not correctly reading or processing my .streamlit/packages.txt file during the build process, which is why the required system library libGL.so.1 is missing at runtime.

Could someone please help me understand why packages.txt might not be processed

Thank you in advance for any assistance!