ImportError: libGL.so.1 while trying to run a Detecto app

Good day!

I am trying to translate this Detecto sample code on a Colab notebook as a Streamlit app, as practice for a future re-implementation for my project’s purposes. I was successfully able to run the translated app locally on my workstation. But as I was testing the very same code on Streamlit Cloud via a Github repo, I am getting the error:

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

As I understand from searching for info about this error, it stems from the use of opencv-python as a dependency, so I followed the advice on Streamlit’s knowledge base and included opencv-python-headless in my requirements.txt file. As I rebooted the app, it returned the very same error, which I suspect is because Detecto lists opencv-python as its dependency.

How can I work around this issue then? Any form of insight will be appreciated :slight_smile:

EDIT: Here is the screenshot of the error as seen in the Streamlit Cloud version:

And here is how it looks like in my local setup:


Of which the end output is going to be labeled dogs, as intended by Detecto’s developers, but in a pretty layout that Streamlit is known for:

Hi @JuliusSempio :wave:

If opencv-python is a required dependency for detecto, and opencv-python requires libGL.so.1:

  1. Create a packages.txt file with the following line

    libgl1
    

Now, when you run from detecto import core, utils, visualize, it should work.

Here’s an example repo with the changes: GitHub - snehankekre/detecto-opencv-test

I will also update the KB article with this solution.

Happy Streamlit-ing, :balloon:
Snehan

Source: python - ImportError: libGL.so.1: cannot open shared object file: No such file or directory - Stack Overflow

1 Like