Frank AK
Frank AK

Reputation: 1781

opencv have different version with python module

I have install the opencv to my ubuntu 14.04LTS,But I have got two version .After I have done the install.I try the below command:

pkg-config --modversion opencv

I got the version: 3.0.0 And when i work it on python shell

>>import cv2
>>cv2.__version__
'2.4.8'

When I follow this http://docs.opencv.org/trunk/d5/d26/tutorial_py_knn_understanding.html#gsc.tab=0 I got some error said 'cv2 have not module 'ml''so,I find it's because i guess my opencv version did't match this tutorial! Can anyone help, why my opencv did't match the python mudule?

Upvotes: 1

Views: 3371

Answers (1)

zedman9991
zedman9991

Reputation: 159

One more step is needed. You need to symbolically link your newly created library file -cv2.so- to your python package path. Details can be found in the last part of this instruction PyImageSearch article - Install OpenCV 3.0 and Python 2.7+ on Ubuntu

Since you already have OpenCV installed a linked library file already exists and you will need to remove it first. From a Docker Ubuntu 14.04LTS instance here if I run the 'file' command below it shows:

file /usr/local/lib/python2.7/site-packages/cv2.so

/usr/local/lib/python2.7/site-packages/cv2.so: symbolic link to `/usr/lib/python2.7/dist-packages/cv2.so'

So you need to remove that symbolic link with 'rm' and create a new one with this command:

ln -s ~path to your new cv2.so file~ /usr/local/lib/python2.7/site-packages/cv2.so

With that you should be able to fire up python, import cv2, and confirm the new version of OpenCV is enabled. Enjoy the tutorial.

Upvotes: 1

Related Questions