1

Hi I have a raspberry pi 2 model B with raspbain installed on it, I want to do machine vision applications so I installed openCV 3.0.0 version with Python 3+ following this tutorial: http://www.pyimagesearch.com/2015/07/27/installing-opencv-3-0-for-both-python-2-7-and-python-3-on-your-raspberry-pi-2/#comment-364261

I wanted to compile my first program (which I took from here https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html#display-image):

import numpy as np
import cv2
img = cv2.imread('messi5.jpg',0)
cv2.imshow('image',img)
k = cv2.waitKey(0)
if k == 27:    
    cv2.destroyAllWindows()

and I get this error:

ImportError: No module named cv2.cv

so searching for help I found this: OpenCV - cannot find module cv2 and added:

import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')

to my code (changing python2.7 for python3.2 because that's the one I have) and now the error I get is this:

ImportError: /home/pi/cv2.so: undefined symbol: _PyUnicode_AsString

I also verified that openCV is correctly installed typing the following command in the terminal:

$ workon cv
$ python
>>> import cv2
>>> cv2.__version__
'3.0.0'

So that's all I did, I'm new to Linux, RPi, Python and openCV. I deeply aprreciate your help, thanks a lot

Community
  • 1
  • 1
  • I think you might have installed opencv for python-3 and trying to import it in python-2.7, thats when this error comes. Am I right? can you check it once by importing cv2 in python-3? – krishna chaitanya Oct 02 '17 at 12:38
  • @krishnachaitanya so if I want to use cv2 in python2.7 I need to reinstall opencv if I installed for python-3? – Lightsout Jun 21 '18 at 02:45
  • @bakalolo I don't have the same environment during which I posted this comment to test again and say it with confidence. As far as I remember, yes you need to reinstall. – krishna chaitanya Jun 23 '18 at 18:01

0 Answers0