Opencv_python3 is disabled by default, so that opencv python is NOT built

Hi, all:

I still cannot have opencv-python built.

During ccmake configuration, there is NO option for me to turn ON opencv_python3. And I did the following search, and opencv_python3 has been turned OFF by default.

➜  build git:(4.x) ✗ grep -rwn "opencv_python3" 
CMakeCache.txt:3665://Module opencv_python3 can not be built in current configuration
CMakeCache.txt:5300://Location of opencv_python3 module sources
CMakeCache.txt:5302://Optional dependencies of opencv_python3 module
CMakeCache.txt:5304://Optional private dependencies of opencv_python3 module
CMakeCache.txt:5306://Required private dependencies of opencv_python3 module
CMakeCache.txt:5308://Required dependencies of opencv_python3 module
CMakeCache.txt:5310://List of wrappers supporting module opencv_python3

So, anybody knows why? And how to build out opencv python ? Thank you …

Did you specify the location of the python libs etc.?


where, on what and how ?

PYTHON3_EXECUTABLE               /usr/bin/python
PYTHON3_INCLUDE_DIR              /usr/include/python3.10           
PYTHON3_LIBRARY                  /usr/lib/x86_64-linux-gnu/
PYTHON3_NUMPY_INCLUDE_DIRS       ~/.local/lib/python3.10/site-packages/numpy/core/include/numpy
PYTHON3_PACKAGES_PATH            lib/python3.11/dist-packages

Can you post your cmake command line arguments and the output from cmake configuration stage. E.g. If append the below to my CMake arguments

-DBUILD_opencv_python3=ON -DPYTHON3_INCLUDE_DIR=/home/b/mambaforge/include -DPYTHON3_LIBRARY=/home/b/mambaforge/lib/ -DPYTHON3_EXECUTABLE=/home/b/mambaforge/bin/python3 -DPYTHON3_NUMPY_INCLUDE_DIRS=/home/b/mambaforge/lib/python3.9/site-packages/numpy/core/include -DPYTHON3_PACKAGES_PATH=/home/b/mambaforge/lib/python3.9/site-packages/

the configuration output is

--   Python 3:
--     Interpreter:                 /home/b/mambaforge/bin/python3 (ver 3.9.15)
--     Libraries:                   /home/b/mambaforge/lib/ (ver 3.9.15)
--     numpy:                       /home/b/mambaforge/lib/python3.9/site-packages/numpy/core/include (ver 1.24.2)
--     install path:                lib/python3.9/site-packages/cv2/python-3
--   Python (for build):            /home/b/mambaforge/bin/python3


Thank you… I found 1 issue: Python imcompatibility. I did have an additional Python which is now removed.

The final issue for now:

  • If I turn ON BUILD_opencv_dnn, I was having a whole bunch of errors
  • If I turn OFF BUILD_opencv_dnn, I failed to build
In file included from ....../opencv/modules/python/src2/cv2.cpp:11:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_include.h:54:10: fatal error: opencv2/dnn/dnn.hpp: No such file or directory
   54 | #include "opencv2/dnn/dnn.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:79: modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '....../opencv/build'
make[1]: *** [CMakeFiles/Makefile2:5932: modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make[1]: Leaving directory '....../opencv/build'
make: *** [Makefile:169: all] Error 2

It looks it’s still the incompatiblity of Caffe after having BUILD_opencv_dnn turned ON.

Any further suggestions?

If you post the configuration arguments you pass to CMake and your CMake configuration ouput I will take a look.

Take a look at my CMakeCache.txt with password 12345678 Thank you …

Unfortunately I don’t have time to sift through that, I need your CMake args and config so I can quickly see if I can reproduce your issue.

I’ve been using ccmake instead of cmake. Don’t know how to provide you the cmake configuration.

General configuration for OpenCV 4.8.0-dev =====================================
   Version control:               4.8.0-1-g131dab774c-dirty

   Extra modules:
     Location (extra):            ~/Downloads/computervision/opencv_contrib/modules
     Version control (extra):     4.7.0-73-gf10c84d4-dirty

     Timestamp:                   2023-06-30T04:36:23Z
     Host:                        Linux 5.19.0-46-generic x86_64
     CMake:                       3.26.4
     CMake generator:             Unix Makefiles
     CMake build tool:            /usr/bin/gmake
     Configuration:               Release

   CPU/HW features:
     Baseline:                    SSE SSE2 SSE3
       requested:                 SSE3
     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
       SSE4_1 (14 files):         + SSSE3 SSE4_1
       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
       AVX (3 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
       AVX2 (28 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
       AVX512_SKX (3 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

     Built as dynamic libs?:      YES
     C++ standard:                11
     C++ Compiler:                /usr/bin/c++  (ver 11.3.0)
     C++ flags (Release):         -std=c++17 -fPIC   -fsigned-char -ffast-math -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized
 -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fno-omit-frame-pointer -pg -g  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -O3
     C++ flags (Debug):           -std=c++17 -fPIC   -fsigned-char -ffast-math -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized
 -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fno-omit-frame-pointer -pg -g  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -g  -O0
     C Compiler:                  /usr/bin/cc
     C flags (Release):           -fPIC   -fsigned-char -ffast-math -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized
 -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fno-omit-frame-pointer -pg -g  -msse -msse2 -msse3 -fvisibility=hidden -fopenmp -O3 -DNDEBUG  -DNDEBUG
     C flags (Debug):             -fPIC   -fsigned-char -ffast-math -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized
 -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fno-omit-frame-pointer -pg -g  -msse -msse2 -msse3 -fvisibility=hidden -fopenmp -g  -O0 -DDEBUG -D_DEBUG
     Linker flags (Release):      -Wl,--as-needed -Wl,--no-undefined
     Linker flags (Debug):        -Wl,--as-needed -Wl,--no-undefined
     ccache:                      NO
     Precompiled headers:         NO
     Extra dependencies:          m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu
     3rdparty dependencies:

   OpenCV modules:
     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv datasets dpm face features2d flann freetype
 fuzzy hdf hfs highgui img_hash imgcodecs imgproc intensity_transform java line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching tracking ts video videoio
 videostab xfeatures2d ximgproc xobjdetect xphoto
     Disabled:                    dnn world
     Disabled by dependency:      dnn_objdetect dnn_superres mcc text wechat_qrcode
     Unavailable:                 gapi julia matlab ovis python2 viz
     Applications:                apps
     Documentation:               NO
     Non-free algorithms:         YES

   GUI:                           QT6
     QT:                          YES (ver 6.2.4 )
       QT OpenGL support:         YES (Qt6::OpenGL )
     GTK+:                        YES (ver 3.24.33)
       GThread :                  YES (ver 2.72.4)
       GtkGlExt:                  NO
     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/

   Media I/O:
     ZLib:                        /usr/local/lib/ (ver 1.2.11)
     JPEG:                        /usr/lib/x86_64-linux-gnu/ (ver 80)
     WEBP:                        /usr/lib/x86_64-linux-gnu/ (ver encoder: 0x020f)
     PNG:                         /usr/lib/x86_64-linux-gnu/ (ver 1.6.37)
     TIFF:                        /usr/lib/x86_64-linux-gnu/ (ver 42 / 4.3.0)
     JPEG 2000:                   OpenJPEG (ver 2.5.0)
     OpenEXR:                     /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ (ver 2_5)
     GDCM:                        YES (3.0.10)
     HDR:                         YES
     SUNRASTER:                   YES
     PXM:                         YES
     PFM:                         YES

   Video I/O:
     DC1394:                      YES (2.2.6)
     FFMPEG:                      YES
       avcodec:                   YES (60.3.100)
       avformat:                  YES (60.3.100)
       avutil:                    YES (58.2.100)
       swscale:                   YES (7.1.100)
       swresample:                YES (4.10.100)
     GStreamer:                   YES (1.20.3)
     v4l/v4l2:                    YES (linux/videodev2.h)
     gPhoto2:                     YES

   Parallel framework:            OpenMP

   Trace:                         YES (built-in)

   Other third-party libraries:
     VA:                          YES
     Lapack:                      YES (/usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/
     Eigen:                       YES (ver 3.4.0)
     Custom HAL:                  NO
     Protobuf:                    /usr/local/lib/ (4.23.0)
     Flatbuffers:                 builtin/3rdparty (23.5.9)

     NVIDIA GPU arch:             80 86
     NVIDIA PTX archs:  

   cuDNN:                         YES (ver 8.9.2)

   Python 3:
     Interpreter:                 /usr/bin/python3 (ver 3.10.6)
     Libraries:                   /usr/lib/x86_64-linux-gnu/ (ver 3.10.6)
     numpy:                       ~/.local/lib/python3.10/site-packages/numpy/core/include (ver 1.25.0)
     install path:                lib/python3.10/dist-packages/cv2/python-3.10

   Python (for build):            /usr/bin/python3

     ant:                         /bin/ant (ver 1.10.12)
     Java:                        NO
     JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include
     Java wrappers:               YES (ANT)
     Java tests:                  NO

   Install to:                    /usr/local

 Configuring done (4.1s)

Can you please help to take a look anyway?? Cheers

If your using cuda 12.2 you probably have this issue as your error is coming from the dnn module

1 Like

Good to know…
I am using Cuda 12.2.

  • However, it looks to me: my ERRORs are more like a protobuf issue?
  • And, which version of protobuf are you using ?
  • And under Ubuntu 22.04, which version of protobuf do you recommend? I’m building protobuf from source anyway…