Import error for cv2

I tried using import cv2 and various combinations of opencv and cv2 codes in the requirements.txt as well as the app.py.

I get this ImportError:

  File "/home/user/.local/lib/python3.8/site-packages/cv2/__init__.py", line 8, in <module>
    from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

I’ve seen a couple of Spaces that have the same error, and have not been able to see a Space that does deploy a program with a cv2 successfully. I would suggest leads on how to address this Import Error, or some samples of working code.

Thank you!

Maria

Hey there!

You can create a packages.txt file and use python3-opencv there. I think this worked for me last time I checked. Let me know if that works please :slight_smile:

Thanks,
Omar

Hi @osanseviero, I tried your suggestion, and I think it worked because although I am still getting an error, it is no longer about cv2.

Thank you!

:slight_smile:
Maria

2 Likes

@osanseviero – I can now confirm that your suggestion was essential in making my project work. Thank you again! :slight_smile:

Maria

2 Likes