So my case is a tricky one.
I first installed OpenCV2.4.8 and started it using for python2.7. Later I planned to migrate to OpenCV3.0.0. Both the times during installation I followed the official documentation procedure. Everything was working fine until I realized that OpenCV3 doesn't have SIFT()
and SURF()
modules. After a bit of searching I found they are present in opencv_contrib. First I tried to install that but for some reason I couldn't.
Later I found that these modules are present in OpenCV2.4.11 and planned to install that. Again following the official procedure I installed OpenCV2.4.11 got the same SIFT()
importerror. Upon checking the OpenCV __version__
in python2 and python3 I found the following
For checking the version I used the following code:
from cv2 import __version__
print(__version__)
Unfortunately I don't have a lot of memory in /home
, so I had deleted OpenCV2.4.8 and OpenCV3.0.0 build folders after installing. Therefore, I tried to manually remove OpenCV2.4.8 and OpenCV3.0.0 and deleted all opencv the libs from /usr/local/libs/
and sub-directories and all the opencv bins from /usr/local/bins/
(following answer in this question).
After removing all opencv files I again reinstalled OpenCV2.4.11 and tried to run my code. It failed at the import step in python2 giving
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
in python3
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.3.0: cannot open shared object file: No such file or directory
I again checked if OpenCV2.4.11 is present or not and its there but the python hasn't updated the previously stored link to opencv lib. I'm stuck at this error since 2 days with no solution. Any help will be appreciated.
EDIT:
Is there some shared library lookup file which python uses to store all the locations of shared libraries? If not how does this work (how python recognizes where to look for opencv as opencv is not listed in pip freeze
)
EDIT2:
I found another mistake. I hadn't enabled -D BUILD_SHARED_LIBS=ON
before. This time I kept it ON
and rand sudo ldconfig
after make
and make install
. Now I have a libopencv_core.so.2.4
in my /usr/local/lib/
. It is a symlink to libopencv_core.so.2.4.11
present in the same folder. After ldconfig
when I checked for python2 import cv2
didn't show any error but __version__
still shows '2.4.8'
. I double checked for any OpenCV2.4.8 .so file and there are none. How is it still pointing to version '2.4.8'
?
Steps for removal:
sudo apt-get purge libopencv*
import cv2
in python. It should show no cv2 module presentsudo ldconfig
after sudo make install
/usr/local/lib/python2.7/dist-packages/
. For that manually copy from /<opencv-2.4.11 unzip locaiton>/release/lib/cv2.so
to /usr/local/lib/python2.7/dist-packages/
. Use sudo
for permissions.Now import cv2
will work and __version__
is '2.4.11'
.