Forums

ImportError: No module named 'cv2' OpenCV is installed by default but still facing issues in importingf CV2 module

I am running an OpenCV code and its showing error in importing cv2 module, although OpenCV is installed defaultly .

Which Python version are you using? I think we only have cv2 installed for Python 2.7.

Python version is 2.7 i am trying to create web2py app and code is for this app

Are you running the code in a Python 2.7 console? Check the name of the console to make sure.

This is how i am checking errors by running file

image link is here

If you run a file from the editor, it will run it in the default Python for your account, which is 3.5, so that explains the problem. This help page explains how to make it use Python 2.7 instead.

Thanks CV2 error is vansished but now facing issue in resize image module error =

ImportError: No module named resizeimage

What command did you use to install it? Were there any errors?

not installed manually . just tried to install through command

'install --user python-resize-image'

but getting error as

File "<stdin>", line 1 pip install --user python-resize-image ^ SyntaxError: invalid syntax

You need to run the "pip install" command in a bash console, not a Python one. If you need to use it in the code where you're running cv2, start a bash console and run this:

pip2.7 install --user python-resize-image

the resize_image module is installed but now facing some issues in cvtColor Error is

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /root/OpenCV/opencv-2.4.9/modules/imgproc/src/color.cpp, line 3737 Traceback (most recent call last): File "/home/globalstat/web2py/applications/image_resize/controllers/default.py", line 62, in <module> print (get_string(src_path + "b.jpg")) File "/home/globalstat/web2py/applications/image_resize/controllers/default.py", line 22, in get_string img = cv2.cvtColor(img_0, cv2.COLOR_BGR2GRAY) cv2.error: /root/OpenCV/opencv-2.4.9/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function cvtColor

Sorry. None of us at PythonAnywhere have used OpenCV. That looks like it's something you may have to debug yourself or ask someone who knows OpenCV.

okay , can you please check if my path is right

/home/globalstat/web2py/applications/image_resize/controllers

What do you want me to check about it? Right for what?

Thank you the issue is resolved