Solvednvidia docker OpenCV Docker error "ImportError: libSM.so.6: cannot open shared object file: No such file or directory"

I don't have much experience of running the code on docker, I am very new to docker.
I am trying to run my deep learning model on docker. I am using OpenCV for some initial image processing. The problem is even after installing opencv on docker it throws error.
pip list shows

DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
backports.weakref (1.0.post1)
bleach (1.5.0)
funcsigs (1.0.2)
future (0.16.0)
html5lib (0.9999999)
Markdown (2.6.9)
mock (2.0.0)
nltk (3.2.5)
numpy (1.15.4)
opencv-contrib-python (3.4.3.18)
pbr (3.1.1)
pexpect (4.2.1)
pip (9.0.1)
protobuf (3.4.0)
psutil (5.4.0)
ptyprocess (0.5.2)
setuptools (36.6.0)
six (1.11.0)
tensorflow (1.3.0)
tensorflow-tensorboard (0.1.8)
Werkzeug (0.12.2)
wheel (0.30.0)
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Now when I run my program, it throws the following error:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

I searched on google about this error, everywhere they are saying to install some packages. But when I try to install those packages in docker, it throws the some error. This is the command that I am running.

apt install -y libsm6

It throws the following error:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libsm6

I just want to run my code using OpenCV. My code is on Python 2.7v. Any help will be appreciated.

13 Answers

✔️Accepted Answer

I fixed this problem on nvcr.io/nvidia/tensorflow:18.12-py3 with (using solution above):

apt-get update
apt-get install -y libsm6 libxext6 libxrender-dev
pip install opencv-python

Other Answers:

It may be enough to "pip install opencv-python-headless", if you do not need GUI.

Not sure without your dockerfile, but I had the same error for a different problem. The install error might be because your base image is out of date. I'm using ubuntu, so had to run docker pull ubuntu:bionic. Then ended up installing libsm6 libxext6 libxrender-devto fix the python import issue.

apt-get update
apt-get install -y libsm6 libxext6 libxrender-dev libglib2.0-0
pip install opencv-python

I fixed this problem on nvcr.io/nvidia/tensorflow:18.12-py3 with (using solution above):

apt-get update
apt-get install -y libsm6 libxext6 libxrender-dev
pip install opencv-python

This worked!!

More Issues: