Cannot find module cv2 when using OpenCV

0 votes

I am using  Occidentalis OS and have installed OpenCV in it. I get the following message while importing cv2 in a Python program.

pi@raspberrypi~$ python cam.py
Traceback (most recent call last)
File "cam.py", line 1, in <module>
    import cv2
ImportError: No module named cv2

The  cv2.so file is stored in -  /usr/local/lib/python2.7/site-packages/.
Can someone please tell me why this message is popping up and how to solve this?

Apr 29, 2022 in Other DevOps Questions by Kichu
• 19,050 points
600 views

1 answer to this question.

0 votes

This is because python is not able to refer to your default site packages folder.

Add these lines in the code:

import sys

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

Or you can move to /usr/local/lib/python2.7/site-packages directory before running the python command in bash.

I hope this helps.

answered Apr 30, 2022 by narikkadan
• 63,680 points

Related Questions In Other DevOps Questions

0 votes
1 answer

Copy log files to local machines using Jenkins

Try initializing the variables with values according ...READ MORE

answered May 2, 2018 in Other DevOps Questions by ajs3033
• 7,300 points
1,690 views
0 votes
1 answer

modulenotfounderror: no module named 'cv2'

Firstly, please do run these following commands ...READ MORE

answered Feb 8, 2022 in Python by Soham
• 9,710 points
2,499 views
0 votes
1 answer

Section postgresql not found in the database.ini file

Python doesn't know what $FILEDIR is. Try an absolute path ...READ MORE

answered Oct 3, 2018 in Python by Priyaj
• 58,100 points
3,622 views
0 votes
1 answer

Iterating over dictionaries using 'for' loops

key is just a variable name. for key ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 13,300 points
972 views
0 votes
1 answer

Conflicting dependencies of pypyodbc and blpapi

I figured out that pypyodbc only works ...READ MORE

answered Oct 9, 2018 in Python by Priyaj
• 58,100 points
730 views
0 votes
1 answer

Message 'src refspec master does not match any' when pushing commits in Git

Solution. Try git show-ref to see what refs you have. ...READ MORE

answered Apr 30, 2022 in Other DevOps Questions by narikkadan
• 63,680 points
1,072 views
0 votes
1 answer

Conversion failed when converting date and/or time from character string while inserting datetime

The SQL server supports many formats. Most ...READ MORE

answered Apr 30, 2022 in Other DevOps Questions by narikkadan
• 63,680 points
14,809 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP