No Module Named cv2

2023-08-22 16:09:01.380 Uncaught app exception
Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/machine_learning/Streamlit/pages/Face Anonymizer.py", line 1, in <module>
    import cv2
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

requirements.txt file is like

opencv-python-headless
numpy
streamlit
streamlit-webrtc
av
mediapipe

link : https://face-anonymizer.streamlit.app/Face_Anonymizer
github link : https://github.com/NithinM29602/Machine_Learning/tree/main/Streamlit

2023-08-22 16:33:47.873 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/app/machine_learning/Streamlit/pages/Face Anonymizer.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

go this error dude, what to do now

@NithinM29602 you can try to use pipreqs to automatically generate your requirements.txt and try to reboot the website again, watch this article here: How to Auto Generate requirements.txt (Dependencies) in Python - 3 examples

Tried it, But Same error is popping out Bro

@Goyo

@Franky1 @snehankekre

Hey @NithinM29602 :wave:

You need to move your packages.txt to the root of GitHub repository. i.e. out of the Streamlit/ directory.

And you only need to include one package libgl1 in packages.txt.

Once you make the two changes, you should no longer see the ImportError: libGL.so.1: error:

We will better highlight the need for packages.txt to be in the repo root in our Community Cloud documentation:

If packages.txt exists in the root directory of your repository we automatically detect it, parse it, and install the listed packages. You can read more about apt-get in Linux documentation.

Happy Streamlit-ing! :balloon:

1 Like

Thanks Bro, The problem was resolved.
But I got another problem, The frames from the webcam is not displaying out there.

If the model is very high, then it’s impossible with the streamlit to do frame to frame detection. Unfortunately streamlit doesn’t work for large object detection models.

But there is an possible solution. Instead of frame to frame detection, we can capture the image and do prediction with the help of st.camera_input(). For more reference:-

https://poth-holes-detector-system-with-bboxes-v1.streamlit.app/

Thanks for the Information.

st.camera_input() is used to capture the photo right. But I need the real time video frames, so that the model can process those frames and display back to the user.
If there is any other Information related to that, Please share it.

After successful run for a few seconds the video capture stopped and showed these error logs

❗️ The service has encountered an error while checking the health of the Streamlit app: Get "http://localhost:8501/healthz": read tcp 10.12.38.55:60612->10.12.38.55:8501: read: connection reset by peer
❗️ The service has encountered an error while checking the health of the Streamlit app: Get "http://localhost:8501/healthz": read tcp 10.13.42.11:51228->10.13.42.11:8501: read: connection reset by peer
[20:24:57] ❗️ Streamlit server consistently failed status checks
[20:24:57] ❗️ Please fix the errors, push an update to the git repo, or reboot the app.

@Guna_Sekhar_Venkata @Franky1 @snehankekre @Melo04

It’s possible with streamlit webrtc package. Once google it, you can find the results

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