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,040 points
741 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,600 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,865 views
+1 vote
2 answers

When do we use Chef or Azure SDK to create VM and deploy in automation

The solution to the automated deployment in ...READ MORE

answered Aug 21, 2018 in Other DevOps Questions by Priyaj
• 58,020 points
1,305 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,705 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,020 points
3,954 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
1,102 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,020 points
850 views
0 votes
0 answers

Azure DevOps - cannot run installed dotnet tool

I tried to run the dotnet tool ...READ MORE

Mar 27, 2022 in Other DevOps Questions by Kichu
• 19,040 points
594 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