Hermonie Granger
Hermonie Granger

Reputation: 11

Import Error : libopencv_core.so.3.0:cannot open shared file

I am using Ubuntu 12.04. I installed the opencv 3.0-beta version initially. Due to some reasons I switched back to an older version, 2.4.9, after uninstalling the older version using commands:

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

and I removed opencv 3.0.

But now when I use opencv 2.4.9 and import cv2 in Python, it shows

Import Error :libopencv_core.so.3.0:cannot open shared object file: No such file or directory

Does it mean that uninstallation was incomplete. Or is there any way to solve this error and import cv2 for opencv 2.4.9?

Upvotes: 1

Views: 11487

Answers (3)

Gil Cruz
Gil Cruz

Reputation: 21

After compile and install opencv 4.1.1 on my raspberry pi 4 (clean install) I got a similar message when I tried to import cv2 :

(cv) pi@raspberrypi:~ $ python
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libopencv_reg.so.3.3: cannot open shared object file: No such file or directory
>>>

I tried this solution but it didn't work, so I did it in a "dirty" way:

I ran the command

(cv) pi@raspberrypi:~ $ sudo ldconfig -v

I got a bunch of lines. The important ones:

...
/usr/local/lib:
    ....
    libopencv_reg.so.4.1 -> libopencv_reg.so.4.1.1
...

Then I created a symbolic link:

(cv) pi@raspberrypi:~ $ cd /usr/local/lib
(cv) pi@raspberrypi:/usr/local/lib $ sudo ln -s libopencv_reg.so.4.1.1 libopencv_reg.so.3.3

Finally, It worked!

(cv) pi@raspberrypi:~ $ python
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.1'
>>>

After rebooting my raspberry pi and import cv2 again, new .so files were "missing" so I repeated the last step for all the other libopencv_*.so.4.1.1 files in '/usr/local/lib'

sudo ln -s libopencv_<<other_lib>>.so.4.1.1 libopencv_<<other_lib>>.so.3.3

Upvotes: 1

kat
kat

Reputation: 615

I ran find/remove for all of the following before I was able to reinstall successfully (I think lines 2 and 4 are the most important though):

sudo find / -name "*opencv*" -exec rm -i {} \;
sudo find / -name "*opencv*" -exec rm -r {} \;
sudo find / -name "*OpenCV*" -exec rm -i {} \;
sudo find / -name "*OpenCV*" -exec rm -r {} \;
sudo find / -name "*cv2*" -exec rm -i {} \;
sudo find / -name "*cv2*" -exec rm -r {} \;

I am using the script from this page for installation: https://help.ubuntu.com/community/OpenCV.

Upvotes: 0

Javonne Martin
Javonne Martin

Reputation: 86

I had the same problem. I fixed this by removing a cv2 file located in "/usr/local/lib/python2.7/dist-packages" for the python2.7 version and removed another cv2 file in "/usr/local/lib/python3.4/dist-packages" for python 3.4 I forgot what the exact names of the files are but you should see it.

Upvotes: 1

Related Questions