Removing all installed OpenCV libs
Asked Answered
G

10

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

Gearbox answered 14/2, 2012 at 11:38 Comment(0)
E
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! :)

Edible answered 14/2, 2012 at 14:21 Comment(4)
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.Gearbox
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.Teleplay
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*" -deleteSever
@Sever 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.Edible
H
20

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

Hypochlorite answered 12/6, 2018 at 3:45 Comment(2)
The space between {bin, lib} makes it look like two separate paths on my Ubuntu 16.04. It should be {bin,lib}.Degradable
should be $ sudo rm -r /usr/local/{bin,lib}/*opencv* to erase even opencv folders?Digamy
N
6

You can do a sudo make uninstall for a clean uninstall

Near answered 14/3, 2014 at 6:47 Comment(1)
In my case, and perhaps the flak37's, there was an error with using make to uninstall opencv.Torero
P
5

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*";

Photoflood answered 4/3, 2020 at 10:11 Comment(0)
U
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.

Unplaced answered 29/9, 2016 at 10:1 Comment(5)
😲 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.Enface
@Enface use -iname instead for case insensitivityNatascha
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.Enface
@Enface if i wish to completely delete opencv why would there be files with the name opencv that i do not want to remove?Predisposition
@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.Enface
W
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

Wherewith answered 2/12, 2016 at 18:42 Comment(0)
R
0

for a specific version for example 3.2:

sudo find / -name "*opencv*3.2*"   -exec rm -rf {} \;
Righteous answered 7/11, 2019 at 9:23 Comment(0)
E
0
sudo rm /home/god/softwares/miniconda3/{bin,lib}/*opencv* 
Enenstein answered 5/4, 2020 at 14:49 Comment(1)
you should replace path of directory .Enenstein
C
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
Chaffee answered 15/6, 2021 at 15:58 Comment(0)
E
0

I used mevatron linux command and encountered a problem that the files in $HOME/opencv/ and $HOME/opencv_contrib/ also got deleted. I recommand the following modified version:

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

The -rI is to avoid the endless prompt asking for permission and delete directory as well.

Emrich answered 19/6 at 3:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.