Marko
Marko

Reputation: 177

Error trying to import cv2(opencv-python) package

I am trying to access my webcam with cv2(opencv-python) package.

When I try to import it I get this error:

Traceback (most recent call last):
  File "server.py", line 6, in <module>
    import cv2
  File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 5, in <module>
    from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Note: I am trying to import this package on putty, on Linode server - that might be useful information.

If anyone can explain to me what is happening and maybe solve the problem I will highly appreciate it!

Upvotes: 12

Views: 21080

Answers (2)

Kaveh P. Yousefi
Kaveh P. Yousefi

Reputation: 185

this worked for me:

conda install -c fastai opencv-python-headless

Upvotes: 1

skvark
skvark

Reputation: 2321

Install opencv-python-headless instead of opencv-python. Server (headless) environments do not have GUI packages installed which is why you are seeing the error. opencv-python depends on Qt which in turn depends on X11 related libraries.

Other alternative is to run sudo apt-get install -y libgl1-mesa-dev which will provide the missing libGL.so.1 if you want to use opencv-python. The libgl1-mesa-dev package might be named differently depending on your GNU/Linux distribution.

Full installation guide for opencv-python can be found from the package documentation: https://github.com/skvark/opencv-python#installation-and-usage

Upvotes: 46

Related Questions