OpenCv is installed, but module cannot be found, how to make sym-link point to cv2.so file?

834 Views Asked by At

I just followed a tutorial to install virtualenv, and opencv3.3.0 on my raspberry pi, running on raspbian (for robots) 3. The virtualenv is installed properly, and I know that opencv is installed as well because workon cv works. However, I am receiving these errors:

(cv) pi@dex:~/opencv-3.3.0 $ python
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] 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: No module named 'cv2'
>>> 

From the tutorial, it was suggested that my sym-link does not point to my cv2.so file. I am brand new to Python and I have no clue what a sym-link even is, let alone how to make it point to my cv2.so file.

(cv) pi@dex:~/opencv-3.3.0 $ sudo find / -name "cv.py"
/usr/lib/python2.7/dist-packages/cv.py
find: ‘/run/user/1000/gvfs’: Permission denied
find: ‘/proc/1083/task/1083/net’: Invalid argument
find: ‘/proc/1083/net’: Invalid argument
find: ‘/proc/1084/task/1084/net’: Invalid argument
find: ‘/proc/1084/net’: Invalid argument
(cv) pi@dex:~/opencv-3.3.0 $ sudo find / -name "cv2.so"
/usr/lib/python2.7/dist-packages/cv2.so
find: ‘/run/user/1000/gvfs’: Permission denied
find: ‘/proc/1083/task/1083/net’: Invalid argument
find: ‘/proc/1083/net’: Invalid argument
find: ‘/proc/1084/task/1084/net’: Invalid argument
find: ‘/proc/1084/net’: Invalid argument

Tutorial reference: https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/

I would appreciate any help i can get. I have searched all over the internet for a solution or guidance through this problem to no avail. I am brand new to python, and linux so please forgive me if I forgot anything, or if i am missing something simple and obvious. Thank you for your time.

2

There are 2 best solutions below

2
On

You have installed openCV in python2.7 and you're using python3.5! To install it use pip3 instead of pip!

First install pip3 :

sudo apt install python3-pip 

Then install opencv:

pip3 install opencv-python --user
4
On

I had this issue once when working on linux and this worked for me

pip install opencv-python