0

I cannot install OpenCV on RaspberryPi 4 Model B with Bookworm OS. I tried at least 4 different ways including pip and cmake. Each time I reach the step to install OpenCV, it ends in failure: cannot build wheel for Numpy. I inslalled puthon 3.11.2 and Numpy 1.26.3. Can anybody help me? This is one of the procedures I follow:

$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 12 (bookworm) Release: 12 Codename: bookworm $ getconf LONG_BIT 64 $ echo $(nproc) 4 $ free -h total used free shared buff/cache available Mem: 3.7Gi 431Mi 2.8Gi 42Mi 635Mi 3.3Gi Swap: 99Mi   0B   99Mi

$ sudo apt-get update && sudo apt-get upgrade $ sudo apt-get install build-essential cmake git pkg-config $ sudo apt-get install python3-dev python3-numpy $ sudo apt-get install python-dev python-numpy $ sudo apt-get install libjpeg-dev libpng-dev $ sudo apt-get install libavcodec-dev libavformat-dev $ sudo apt-get install libswscale-dev libdc1394-22-dev $ sudo apt-get install libv4l-dev v4l-utils $ sudo apt-get install libgtk2.0-dev libcanberra-gtk* libgtk-3-dev $ sudo apt-get install libtbb2 libtbb-dev $ cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D ENABLE_NEON=ON
-D ENABLE_VFPV3=ON
-D BUILD_ZLIB=ON
-D BUILD_OPENMP=ON
-D BUILD_TIFF=OFF
-D BUILD_OPENJPEG=OFF
-D BUILD_JASPER=OFF
-D BUILD_OPENEXR=OFF
-D BUILD_WEBP=OFF
-D BUILD_TBB=ON
-D BUILD_IPP_IW=OFF
-D BUILD_ITT=OFF
-D WITH_OPENMP=ON
-D WITH_OPENCL=OFF
-D WITH_AVFOUNDATION=OFF
-D WITH_CAP_IOS=OFF
-D WITH_CAROTENE=OFF
-D WITH_CPUFEATURES=OFF
-D WITH_EIGEN=OFF
-D WITH_GSTREAMER=ON
-D WITH_GTK=ON
-D WITH_IPP=OFF
-D WITH_HALIDE=OFF
-D WITH_VULKAN=OFF
-D WITH_INF_ENGINE=OFF
-D WITH_NGRAPH=OFF
-D WITH_JASPER=OFF
-D WITH_OPENJPEG=OFF
-D WITH_WEBP=OFF
-D WITH_OPENEXR=OFF
-D WITH_TIFF=OFF
-D WITH_OPENVX=OFF
-D WITH_GDCM=OFF
-D WITH_TBB=ON
-D WITH_HPX=OFF
-D WITH_EIGEN=OFF
-D WITH_V4L=ON
-D WITH_LIBV4L=ON
-D WITH_VTK=OFF
-D WITH_QT=OFF
-D BUILD_opencv_python3=ON
-D BUILD_opencv_java=OFF
-D BUILD_opencv_gapi=OFF
-D BUILD_opencv_objc=OFF
-D BUILD_opencv_js=OFF
-D BUILD_opencv_ts=OFF
-D BUILD_opencv_dnn=OFF
-D BUILD_opencv_calib3d=OFF
-D BUILD_opencv_objdetect=OFF
-D BUILD_opencv_stitching=OFF
-D BUILD_opencv_ml=OFF
-D BUILD_opencv_world=OFF
-D BUILD_EXAMPLES=OFF
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages
-D OPENCV_ENABLE_NONFREE=OFF
-D OPENCV_GENERATE_PKGCONFIG=ON
-D INSTALL_C_EXAMPLES=OFF
-D INSTALL_PYTHON_EXAMPLES=OFF .. $ make -j$(nproc) $ sudo make install $ sudo ldconfig $ sudo apt-get update $ cd ~ $ sudo rm -rf opencv $ python3 3.11.2 import cv2

6
  • Does anyone actually read the documentation? If you want to use it install using apt. Why (and how) did you install python 3.12? If you really need to do this you will have to build (and manage) the dependencies in a virtual environment.
    – Milliways
    Jan 15 at 21:03
  • I have to admit that I didn’t read the documentation (of OpenCv if that’s what you asking) but for sure I will read it now. Please be aware that I am not an expert in installation and configuration but I can do some coding. The truth is that I used virtual environment when doing a new installation and I get the same error. So I guess I need some little explanation now: Python and pip are installed first and then everything else will be installed inside the virtual environment or…? Jan 16 at 2:56
  • I was actually talking about the Raspberry Pi OS documentation. If you want to use an extra python version this should also be installed in a virtual environment.
    – Milliways
    Jan 16 at 2:59
  • Edited the question: Actually it's python 3.11.2 ( I think I mistyped two digits, sorry) Jan 16 at 13:29
  • Does this answer your question? Can't install Opencv on raspberry pi 4
    – Milliways
    Feb 16 at 0:11

1 Answer 1

0

Whatever you have now "I inslalled(sic) puthon(sic) 3.11.2 and Numpy 1.26.3" you have probably made a mess of your system.

I suggest you restore from your backup (or do a fresh install) and start again.

DO NOT attempt to install using pip install using apt.

DO NOT use apt-get use apt.

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.