37

I'm running Kubuntu 11.10 (w/ KDE 4.8)

Before you read all this :

I just want to remove all traces of OpenCV from my system, so I can start afresh..

The whole story

I first installed python-opencv and libopencv (2.1 I think) from https://launchpad.net/~gijzelaar/+archive/opencv2 a long time ago. I only tried python-opencv at that time, which worked perfectly (I didn't attempt using C++ code using OpenCV)

Then I recently tried to install OpenCV 2.3.1 from source, which got installed but while compiling my own C++ code (using OpenCV), it gave me errors about libgtk not installed and also broke my python opencv code which was running fine earlier

So I installed the libgtk2-dev libraries and compiled and installed OpenCV 2.3.1 again..

The error still occured, so I deleted the untarred OpenCV directory from which I was running cmake, make ,etc. I did NOT make uninstall (which I now realize was my mistake)

and instead installed the ubuntu opencv 2.3 package (with all dependencies) from here : https://launchpad.net/~gijzelaar/+archive/opencv2.3

Now the problem is I still get the same error when I compile my C++ code which includes OpenCV , and the error still points to my (deleted) OpenCV source folder :

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 cvNamedWindow, file /home/anant/opencv/OpenCV-2.3.1/modules/highgui/src/window.cpp, line 275
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/anant/opencv/OpenCV-2.3.1/modules/highgui/src/window.cpp:275: 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 cvNamedWindow

As you can see the error still points to the directory from where I had compiled and installed OpenCV

Is there a way to completely remove all traces of my compiled version of OpenCV and just keep the files from the ubuntu package? As I mentioned earlier I did not 'make uninstall' and have also (foolishly) deleted the install-manifest

EDIT: I ran the package manager again,and found that not all opencv packages from the ppa had gotten installed properly. So I did a sudo apt-get install opencv again, and now I get this error:

Unpacking libopencv2.3 (from .../libopencv2.3_2.3.1-3_amd64.deb) ...
dpkg: error processing /var/cache/apt/archives/libopencv2.3_2.3.1-3_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/libopencv_video.so.2.3.1', which is also in package libopencv-video2.3 2.3.1-4ppa1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Unpacking opencv (from .../opencv_2.3.1-3_amd64.deb) ...
dpkg: error processing /var/cache/apt/archives/opencv_2.3.1-3_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/opencv_haartraining', which is also in package libopencv-core-dev 2.3.1-4ppa1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libopencv2.3_2.3.1-3_amd64.deb
 /var/cache/apt/archives/opencv_2.3.1-3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I just want to remove all traces of OpenCV from my system, so I can start afresh

flak37
  • 885
  • 2
  • 10
  • 18

9 Answers9

58

By default, when building OpenCV from source, it will place it's output in /usr/local/lib and /usr/local/bin. Although, judging from your error messages, it looks like it placed the libraries in /usr/lib and the binaries in /usr/bin, so you might also check in there.

You can also use the Linux find command. So, to find all OpenCV libraries you can do the following (this might take a while):

$> sudo find / -name "*opencv*" -exec rm -i {} \;

The above command will find any file containing opencv in the name, and will prompt you to remove it. As always, be careful when deleting things manually!

Another option might be to manually compile OpenCV again (exactly as you did before), make install to create the install manifest, and then try make uninstall to see if it will clean up itself.

Hope that helps! :)

mevatron
  • 13,911
  • 4
  • 55
  • 72
  • 1
    Thanks! Just what I was looking for. I uninstalled the packages, then ran sudo find / -name "*opencv*" -exec rm -i {} \; then reinstalled the packages. Fixed my last error by running sudo dpkg -i --force-overwrite path-to-package. OpenCV seems to work now, though I'm yet to test it thoroughly. Python-OpenCV is working like before. – flak37 Feb 14 '12 at 15:39
  • Another related suggestion would be to install OpenCV in a virtual machine next time you need to use it; that way when it's time to uninstall all you've gotta do is destroy the VM and *poof*, you're done. – the911s Jul 07 '14 at 21:30
  • 3
    Not a good answer, regarding the `find` command. This will delete anything, even in your user directory or other users' directories, which by chance may haven opencv in it (e.g. own scripts, files, files from other libraries, etc). very dangerous, I'd not use it. If you really have to delete these files, be veery careful and also test if the versions interfere with apt-packages: `sudo find /usr/ -name "*opencv*3.4*" -delete` – DomTomCat Aug 29 '18 at 09:27
  • 2
    @DomTomCat Yes, you can definitely filter the start directory like that. I'd also recommend using rm -i for interactive mode to make sure you want to actually delete the file. – mevatron Aug 29 '18 at 17:31
18

If you have the build directory then it is recommended to execute:

 $ sudo make uninstall

from the build directory as per @Navid 's answer

But this will leave few .so* files somewhere

To completely remove all such files, do:

$ sudo rm /usr/local/{bin,lib}/*opencv* 

/usr/local is what we normally set CMAKE_INSTALL_PREFIX to while running cmake. Replace it according to how you executed cmake

Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
sziraqui
  • 5,763
  • 3
  • 28
  • 37
6

You can do a sudo make uninstall for a clean uninstall

Navid
  • 384
  • 2
  • 7
4

I couldn't find the build directory so did:

sudo apt-get purge '*opencv*'

And:

sudo find / -name "*opencv*" -exec rm -rf {} \;

Which seems to have worked fine.

You can double check with:

sudo find / -name "*opencv*";

Josh
  • 2,122
  • 1
  • 21
  • 28
3

In order to remove all the files and folders without "interaction", use the below command :

sudo find / -name "*opencv*" -exec rm -rf {} \;

CAUTION: It's not advisable to run "recursive" and "force" deletion.

loki
  • 9,816
  • 7
  • 56
  • 82
  • 7
    in case anyone else sees this (upvoted?) answer & is thinking of running it -- please don't. Instead do something like (note: checking for upper/lower, there's both): `sudo find / \( -name "*opencv*" -o -name "*OpenCV*" \) -print 2>/dev/null > /tmp/out.txt` and manually inspect `/tmp/out.txt` for things you want to remove. Running the above command would be kinda crazy. Another thing to try (but is not exhaustive) is `locate -i opencv`. You'll quickly definitely notice that there's things you _do not want to remove_. – michael Oct 19 '17 at 06:15
  • @michael use `-iname` instead for case insensitivity – linuxUser123 Apr 18 '19 at 12:57
  • I wouldn't use `-iname` for the same reason I recommended not running `-name "*opencv*" `, but rather manual check via `locate -i` (the `locate` is case-insensitive), because there are other names that might match the substring that are still required/desired (eg `libgstreamer1.0-opencv`, etc). Generally, nothing related to OpenCV would be anything other than `opencv` or `OpenCV` (eg, not `MicroPenCVS`), so the precision avoids unwelcome surprises. That being said, I'd _still_ never, ever, ever `find / ... rm` from `/` (root), since that's the pkg mgr domain, but rather only from `/opt`, etc. – michael Apr 22 '19 at 05:39
  • @michael if i wish to completely delete opencv why would there be files with the name opencv that i do not want to remove? – Kong May 15 '20 at 15:54
  • @kong No idea, impossible to say what the case-insensitive wildcard could match in the future (but that's the point). I used the hypothetical package "MicroPenCVS" as an example. Dry-run == measure twice, cut once. – michael May 15 '20 at 22:24
1

If opencv is installed using sudo make install command on source then go to the build folder and use sudo make uninstall and it should uninstall opencv

abggcv
  • 461
  • 5
  • 20
0

for a specific version for example 3.2:

sudo find / -name "*opencv*3.2*"   -exec rm -rf {} \;
sivi
  • 10,654
  • 2
  • 52
  • 51
0
sudo rm /home/god/softwares/miniconda3/{bin,lib}/*opencv* 
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
0

There are some files and folders used by the system containing "opencv" in their name. You definitely do not want to remove them. So I advise against using $ sudo find / -name "*opencv*" -exec rm -rf {} \; to remove opencv, because it recursively deletes all files and folders containing "opencv" in their name.

A better alternative would be to use this command, which prompts you before deleting each of the files and folders found:

$ sudo find / -name "*opencv*" -exec rm -i {} \;

In case you accidentally removed any of the system's native opencv files and broke something (or maybe it seemed like a good idea at the time), here's your fix:

  1. Remove installed opencv libraries
$ sudo apt remove libopencv-dev   
$ sudo apt remove libopencv-core3.2
  1. However, opencv-data might not be removed with this. You can find the remaining files with this:

$ sudo apt list --installed | grep opencv

  1. After that, reinstall the system opencv files with ROS Melodic:

$ sudo apt install ros-melodic-desktop-full

N.B. If you need to set up the source list prior to installing ros melodic, you can use the commands below (execute them before step 3 if step 3 doesn't work for you):

$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

$ sudo apt-get update

$ sudo apt-get install ros-melodic-desktop-full