Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't import cv2 in SageMaker Studio Lab

I tried importing cv2 from opencv but i got error saying

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

Since Sagemaker Studio Labs doesn't support installation of Ubuntu packages i couldn't use apt-get or yum to install libglib2.0-0.

like image 331
Sai Dinesh Pola Avatar asked Oct 27 '25 04:10

Sai Dinesh Pola


2 Answers

You fix this by:

!pip uninstall opencv-python -y

Then use the headless version instead with studio:

!pip install opencv-python-headless

Ref: https://github.com/aws/amazon-sagemaker-examples/issues/1773

like image 58
BenCaldwell Avatar answered Oct 29 '25 05:10

BenCaldwell


With this line, you can install the glib dependency for Amazon Sagemaker Studio Lab. Just run it on your notebook cell.

! conda install glib=2.51.0 -y

You also can create another virtual environment for your session that contains glib:

! conda create -n glib-test -c defaults -c conda-forge python=3 glib=2.51.0` -y

After that maybe you need albumentations to import cv2:

! pip install albumentations
like image 41
DraggonDragger Avatar answered Oct 29 '25 06:10

DraggonDragger