1

I just bought a new camera for my pi so I installed it and then I wanted to test it out so I got a simple python program to test it:

import cv2 as cv 
def testDevice(source):
 cap = cv.VideoCapture(source) 
 if cap is None or not cap.isOpened():
 print('Warning: unable to open video source: ', source)
testDevice(0) # no printout
testDevice(1) # prints message

but when I run this program I get the following error:

Traceback (most recent call last):
 File "/home/pi/Desktop/tests/cam.py", line 1, in <module>
 import cv2 as cv
ImportError: No module named 'cv2'

oh, looks like the module cv2 is missing. Ok I tried to install it two different ways but failed:

pip install opencv-python
ERROR: Command errored out with exit status 1: /usr/bin/python /home/pi/.local/lib/python2.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-G_YoLY/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple --extra-index-url https://www.piwheels.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.11.3; python_version=='"'"'3.5'"'"'' 'numpy==1.13.3; python_version=='"'"'3.6'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"'' Check the logs for full command output.
pip3 install opencv-python
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-8f0epjtp/opencv-python/

Should I use opencv or is there something else? If I should, how do I get it to work?

asked Sep 18, 2020 at 14:34
2
  • 1
    You are going to have to compile it. (Did it myself, took an hour on Pi 4) Search for it on Google. Commented Sep 20, 2020 at 3:30
  • 1
    Does this answer your question? Can't install Opencv on raspberry pi 4 Commented Nov 1, 2023 at 3:45

2 Answers 2

1

I did this exact thing with a fresh installation of pi os and got it succesfully, see screenshot screenPI

answered Jan 14, 2021 at 13:56
1

Okay, I know this question's old, but try to install it again now if you haven't figured it out yet.

Some OpenCV versions were incompatible with RPi back then. But the developers have updated the precompiled binaries numerous times, and now they are pretty stable.

So do give pip3 install opencv-python a try again.

answered Jun 8, 2022 at 17:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.