Import cv2 and other errors

error as follows:

[12:54:58] 🐍 Python dependencies were installed from /app/motion-detector-app/requirements.txt using pip.

[12:54:58] 📦 Processed dependencies!


Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.





[12:55:00] 🔄 Updated app!

2023-01-03 12:55:41.024 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/motion-detector-app/test.py", line 1, in <module>

    import cv2

  File "/home/appuser/venv/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>

    bootstrap()

  File "/home/appuser/venv/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap

    native_module = importlib.import_module("cv2")

  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

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

2023-01-03 12:55:44.474 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/motion-detector-app/test.py", line 1, in <module>

    import cv2

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

github link:GitHub - zaidikram4/motion-detector-app

Follow this url App dependencies - Streamlit Docs

still did’nt work

Try opencv-contrib-python rather than opencv-python.

1 Like

Hi @zaidikram4,

Welcome to the community! :wave: :partying_face:

cv2 should be successfully imported when you only include libgl1 in your packages.txt file:

Remove the contents of your current packages.txt file and replace it with:

libgl1

Happy Streamlit-ing! :balloon:
Snehan

1 Like

Thank you so much Snehan, I was finally able to upload it on the cloud.
After uploading I’m getting a small error though

The issue arises as you’re trying to capture webcam input with OpenCV for an app deployed to Streamlit Cloud. I’ve explained why this isn’t possible and what you can do about it in these threads:

Best,
Snehan

1 Like

Thanks again Snehan.

hey there, i know it is a common problem but its mine too.
I´ve try it to deploy with this tip “ImportError libGL.so.1 cannot open shared object file No such file or directory - Streamlit Docs ”.
I´ve run it in two different machines , in localhost and it works. But i receive always the same message “ImportError: libGL.so.1: cannot open shared object file: No such file or directory” when deploying and several clouds (render, heroku…)

my code, GitHub - jhmax/pipe_pose

help please, and thanks in advance

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.