OpenCV error :- If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config...

Ajaz Ahmed
2 min readOct 12, 2020

I was working with hand gesture detection using OpenCv and got stuck at a place where I could not move further and you know what, the problem was known as

cv2.error: OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474/work/modules/highgui/src/window.cpp:632: error: (-2:Unspecified error) Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'.

I am going to tell you the exact steps on how to solve this problem. One thing we should put in mind is that the main root cause of this problem is OpenCV. One method of OpenCV known as imshow()(written like cv2.imshow()) was creating this problem in my case. I am using ubuntu 20.04 (python 3.6) but this would work with other versions of ubuntu as well.

First you should try to run this command

sudo apt-get install libopencv-*

It will download all the required dependencies like OpenCV.

This should probably solve your problem. If the problem persists after trying this . Then you should try the below command

conda remove opencv
conda install -c conda-forge opencv

If you are using pip then you should try

pip install opencv-contrib-python

I hope this solves your problem. :)

--

--