I have been trying to install opencv on my raspberry pi zero loaded with buster. I have followed a couple of tutorials online with no success. I thought this tutorial worked until I tried to import cv2 in python and it returned "Illegal instruction" and then kicked me out of python. I opened up python again and typed "import garbage" and it returned ModuleNotFoundError: No module named 'garbage' and allowed me to stay in python. I read somewhere online that "Illegal instruction" is displayed when there is a discrepancy in the architecture. This makes sense considering the tutorial was for a raspberry pi 2,3,4 and I am trying to install this on a zero. I am pretty new to this and not certain how to fix this or if it can be fixed. Does anybody have a solution or can point me to a tutorial that was successful installing opencv on a pi zero? Thank you for your time.

2 Answers 2


I don't know what you have tried because I don't follow links to understand a question, but at a glance it seems that you tried to compile ``OpenCV` from source. That is not needed. Just install it from the repository with:

rpi ~$ sudo apt install python3-opencv

If you need additional modules look for them with:

rpi ~$ sudo apt list *opencv*
  • This will not work. The build in the repos is not for arm64 and will throw "Illegal operation" when cv2 is imported. On the pi zero, it seems one absolutely has to build from source.
    – KinsDotNet
    Jan 4, 2022 at 18:47

I got bitten by this issue, too, and managed to solve it. The problem following the build instructions from the link is that the configuration command includes CPU instruction set optimization flags (neon, vfpv3) not supported by the slightly lesser CPU of pi zero.

Change the configuration command to

    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \

That should do the trick. Still, the build takes almost 24h. If you don't need the newest tricks from OpenCV, the solution from Ingo is the best, and I wish I had seen it before spending the days building from the source. (Installed from repository: 3.2.0, self-built: 4.4.0-pre.)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.