Python – Reinstall OpenCV from Scratch

clinuxopencvpythonUbuntu

I'm having an error in OpenCV when I try to run a python code. I tried running

import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread("watch.jpg", cv2.IMREAD_GRAYSCALE)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

But I'm getting this error.

OpenCV Error: Unspecified error (The function is not implemented. 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 cvShowImage, file /home/pankaja/Desktop/OpenCV-tmp/opencv/modules/highgui/src/window.cpp, line 611
Traceback (most recent call last):
File "/home/pankaja/PycharmProjects/ImageProcessing/imageprocess.py", line 8, in
cv2.imshow('image', img)
cv2.error: /home/pankaja/Desktop/OpenCV-tmp/opencv/modules/highgui/src/window.cpp:611: error: (-2) The function is not implemented. 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

with some errors finally I managed to install libgtk2.0-dev and pkg-config (The following packages have unmet dependencies OpenCV 3.2 Python 3.5), but still the it's giving the error

So, now I think of doing to do a fresh installation on both python 3.5 and OpenCV to fix the problem. How can I uninstall OpenCV completely?

Best Answer

I had the same problem once. I fixed the problem by completely uninstalling opencv and reinstalling it from source. There are some dependencies like ffmpeg you should install.

EDIT: To completely uninstall opencv

  1. If you installed from source you can use the following command

    make uninstall

run This command from build directory of the opencv source.

  1. If you installed using pip

    sudo pip uninstall opencv

  2. If you Installed using apt-get

    sudo apt-get remove python-opencv

    sudo apt-get purge python-opencv

I hope this might help

Related Topic