80

i am trying to run cv2, and when i try to import it i get

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

the suggested solution online is installing

apt install libgl1-mesa-glx

but this is already installed and the latest version.Any help would be really helpful.Thanks in advance.

Ryan
  • 4,407
  • 9
  • 29
  • 52
  • How did you install it? `pip install opencv-python`? Could be another issue. See https://github.com/matplotlib/matplotlib/issues/9954. Try creating a virtualenv and test it there. Can you share your code snippet where its throwing the exception? – HariUserX Mar 23 '19 at 12:19
  • I am actually running this on docker, and i am not able to check the open cv version.I tried importing matplotlib and it imports fine. – Ryan Mar 23 '19 at 12:49

5 Answers5

163
RUN apt-get update ##[edited]
RUN apt-get install ffmpeg libsm6 libxext6  -y

Add these lines to your Dockerfile

Community
  • 1
  • 1
Tushar Kolhe
  • 2,097
  • 1
  • 5
  • 11
11

This is a little bit better solution in my opinion. Package python3-opencv includes all system dependencies of OpenCV.

RUN apt-get update && apt-get install -y python3-opencv
RUN pip install opencv-python
Andrej Chudy
  • 121
  • 1
  • 3
  • I'm using `python:buster`. the solution above didn't work for me: `ffmpeg` seems to be deprecated and I still had write errors. `apt-get install -y python3-opencv` did the trick. thanks – Eric F Mar 27 '21 at 14:21
  • This gets just about every lib you could want. I didn't try it, but is pip install still needed? – Mark Carpenter Jr Mar 29 '21 at 23:01
1

Please run the following commands

sudo apt update


sudo apt install libgl1-mesa-glx

Link- https://github.com/conda-forge/pygridgen-feedstock/issues/10

0

Here is the solution you need:

pip install -U opencv-python
apt-get upgrade
apt update && apt install -y libsm6 libxext6 ffmpeg libfontconfig1 libxrender1 libgl1-mesa-glx
Ankur
  • 9
  • 2
0

had the same issue on centos 8 after using pip3 install opencv on a non gui server which is lacking all sorts of graphics libraries.

dnf install opencv

pulls in all needed dependencies.

Jens Timmerman
  • 7,500
  • 1
  • 34
  • 45