'Installation error OpenCV 4.5.5 from source code in Windows

I was trying to install OpenCV-4.5.5 from source on my windows machine. This machine has the latest Nvidia drivers as well as CUDA 11.6, I did not run into any issue with those. On the other hand I wanted to install OpenCV with the GStreamer dependencies, I previously installed the library and had no issues as well.

My main problem is that I wanted to generate the python3 bindings but when I reach the installation part, build already completed without issues, I run into the following error:

CMake Error at C:/OpenCV-4.5.5/build/modules/python3/cmake_install.cmake:153 (file): file INSTALL cannot find "C:/OpenCV-4.5.5/build/lib/python3/Release/cv2.cp39-win_amd64.pyd": File exists. Call Stack (most recent call first): C:/OpenCV-4.5.5/build/cmake_install.cmake:291 (include)

I used a .bat script to configure the CMake build:

-D CMAKE_INSTALL_PREFIX=C:/OpenCV-4.5.5/install ^
-D OPENCV_EXTRA_MODULES_PATH=C:/Users/%USERNAME%/Downloads/opencv_contrib-4.5.5/opencv_contrib-4.5.5/modules ^
-D ENABLE_FAST_MATH=ON ^
-D CUDA_FAST_MATH=ON ^
-D WITH_CUDA=ON ^
-D WITH_CUDNN=ON ^
-D OPENCV_DNN_CUDA=ON ^
-D CUDA_ARCH_BIN=8.6 ^
-D WITH_OPENGL=ON ^
-D WITH_GSTREAMER=ON ^
-D BUILD_opencv_python3=ON ^
-D PYTHON3_EXECUTABLE=C:/Users/%USERNAME%/AppData/Local/Programs/Python/Python39/python.exe ^
-D PYTHON3_INCLUDE_DIR=C:/Users/%USERNAME%/AppData/Local/Programs/Python/Python39/include ^
-D PYTHON3_LIBRARY=C:/Users/%USERNAME%/AppData/Local/Programs/Python/Python39/libs/python39.lib ^
-D PYTHON3_NUMPY_INCLUDE_DIRS=C:/Users/%USERNAME%/AppData/Local/Programs/Python/Python39/Lib/site-packages/numpy/core/include ^
-D PYTHON3_PACKAGES_PATH=C:/Users/%USERNAME%/AppData/Local/Programs/Python/Python39/Lib/site-packages ^
-D CMAKE_CONFIGURATIONS_TYPES=Release ^
-G "Visual Studio 17 2022" ^
-S C:/Users/%USERNAME%/Downloads/opencv-4.5.5/opencv-4.5.5 -B C:/OpenCV-4.5.5/build

The output of the script is this:

--   Version control:               unknown
--
--   Extra modules:
--     Location (extra):            C:/Users/10655707/Downloads/opencv_contrib-4.5.5/opencv_contrib-4.5.5/modules
--     Version control (extra):     unknown
--
--   Platform:
--     Timestamp:                   2022-01-28T07:26:17Z
--     Host:                        Windows 10.0.19044 AMD64
--     CMake:                       3.22.1
--     CMake generator:             Visual Studio 17 2022
--     CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe
--     MSVC:                        1930
--     Configuration:               Debug 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 (18 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (33 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe  (ver 19.30.30709.0)
--     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MD /O2 /Ob2 /DNDEBUG
--     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MDd /Zi /Ob0 /Od /RTC1
--     C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe
--     C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /MP   /MD /O2 /Ob2 /DNDEBUG
--     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /MP /MDd /Zi /Ob0 /Od /RTC1
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/lib/x64 -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/lib
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 alphamat cvv freetype hdf java julia matlab ovis python2 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   Windows RT support:            NO
--
--   GUI:                           WIN32UI
--     Win32 UI:                    YES
--     OpenGL support:              YES (opengl32 glu32)
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.2.11)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES (prebuilt binaries)
--       avcodec:                   YES (58.134.100)
--       avformat:                  YES (58.76.100)
--       avutil:                    YES (56.70.100)
--       swscale:                   YES (5.9.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   YES (1.18.5)
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      YES
--
--   Parallel framework:            Concurrency
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   C:/OpenCV-4.5.5/build/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                C:/OpenCV-4.5.5/build/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--
--   NVIDIA CUDA:                   YES (ver 11.6, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             86
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 8.3.2)
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                C:/Users/10655707/Downloads/opencv-4.5.5/opencv-4.5.5/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 C:/Users/10655707/AppData/Local/Programs/Python/Python39/python.exe (ver 3.9.10)
--     Libraries:                   C:/Users/10655707/AppData/Local/Programs/Python/Python39/libs/python39.lib (ver 3.9.10)
--     numpy:                       C:/Users/10655707/AppData/Local/Programs/Python/Python39/Lib/site-packages/numpy/core/include (ver 1.22.1)
--     install path:                C:/Users/10655707/AppData/Local/Programs/Python/Python39/Lib/site-packages/cv2/python-3.9
--
--   Python (for build):            C:/Users/10655707/AppData/Local/Programs/Python/Python39/python.exe
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    C:/OpenCV-4.5.5/install
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: C:/OpenCV-4.5.5/build

Then, in the build folder, I just did a

cmake --build . --target INSTALL --config Release -j10
cmake --install .

Any idea why I may be running into this issue? I haven't been able to figure out why does this happen only with this binding.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source