Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install python-opencv in amazon-sagemaker?

I installed the OpenCV package by pip install opencv-python.

When I import cv2 in my code.

import cv2

I got the following error:


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_324/571303353.py in <module>
----> 1 import cv2

~/.conda/envs/default/lib/python3.9/site-packages/cv2/__init__.py in <module>
      6 import sys
      7 
----> 8 from .cv2 import *
      9 from .cv2 import _registerMatType
     10 from . import mat_wrapper

ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory

Here are some solutions for this error but seemly need root permission.

apt-get update -y
apt-get install libglib2.0-0

When I run these commands in the terminal I got the following errors.

(studiolab) studio-lab-user@default:~/sagemaker-studiolab-notebooks/vit/ViT-pytorch$ apt-get update -y
Reading package lists... Done
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
like image 869
Ausrada404 Avatar asked Sep 19 '25 23:09

Ausrada404


1 Answers

This problem has been solved.

pip uninstall opencv-python
pip install opencv-python-headless

More details can be found in here.

like image 116
Ausrada404 Avatar answered Sep 22 '25 13:09

Ausrada404