Dylan Mac
Dylan Mac

Reputation: 75

Cmake unable to find Python 3 when configuring openCV

So, I'm trying to install openCV with GPU support on my laptop via cmake. I followed every single step from https://thinkinfi.com/install-opencv-gpu-with-cuda-for-windows-10/ and other tutorials from youtube, and cmake wasn't able to find some Python 3 parameters including Interpreters, Libraries, numpy, and install path. I have tried reinstalling all necessary software from beginning and tried others solution but none of them worked.

To make everything clear, I'll briefly explain what I have done.

  1. Installing anaconda, cmake, VS code 16 2019, CUDA, and cuDNN
  2. Download opencv-4.8.0 and opencv_contrib-4.8.0 from github
  3. Create a build folder inside a folder called "opencv_gpu" which contains: opencv-4.8.0 and opencv_contrib-4.8.0
  4. Configure on cmake with opencv-4.8.0 as the source code and VS code 16 2019 as the generator
  5. Checking unchecked parameters including WITH_CUDA, OPENCV_DNN_CUDA, ENABLE_FAST_MATH, and set the path for OPENCV_EXTRA_MODULES_PATH to D:\opencv_gpu\opencv_contrib-4.8.0\modules
  6. Configure again then check CUDA_FAST_MATH, set CMAKE_CONFIGURATION_TYPES to only Release, and CUDA_ARCH_BIN to 8.6 (My GPU is NVIDIA RTX 3050 and its compute capability is 8.6) you can check here https://en.wikipedia.org/wiki/CUDA
  7. Configure -> Generate
  8. Run this command cmake --build "D:\opencv_gpu\build" --target INSTALL --config Release
  9. Done

This is the warning message I get in every configuration which I believe leads to the error message below

  Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
  are removed.  Run "cmake --help-policy CMP0148" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.

Call Stack (most recent call first):
  cmake/OpenCVDetectPython.cmake:64 (find_host_package)
  cmake/OpenCVDetectPython.cmake:280 (find_python)
  CMakeLists.txt:649 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

and when I try to import cv2 this is the error that it gives (This is done after the whole process)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'

It should produce something like this after the configuration :

.
.
.
--  OpenCl:                         YES(NVD3D11)
--    Include path:                 D:/opencv_gpu/opencv-4.8.0/3rdparty/i
--    Link libraries:               Dynamic load

--   Python 3:
--     Interpreter:                 D:/anaconda3/python.exe (ver 3.10.9)
--     Libraries:                   {path to directory}
--     numpy:                       {path to directory}
--     packages path:               {path to directory}

--  Python (for build):             D:/anaconda3/python.exe
.
.
.

But this is what I get:

.
.
.
--  OpenCl:                         YES(NVD3D11)
--    Include path:                 D:/opencv_gpu/opencv-4.8.0/3rdparty/i
--    Link libraries:               Dynamic load

--  Python (for build):             D:/anaconda3/python.exe
.
.
.

Some other information:

Checking CUDA version to ensure that it's installed nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jul_14_19:47:52_Pacific_Daylight_Time_2021
Cuda compilation tools, release 11.4, V11.4.100
Build cuda_11.4.r11.4/compiler.30188945_0

Some tutorials mention that this problem arises because of having older version of numpy. So I run the command and it seems like I have the latest version of numpy pip install --upgrade numpy

Requirement already satisfied: numpy in d:\anaconda3\lib\site-packages (1.25.1)

Upvotes: 1

Views: 791

Answers (0)

Related Questions