I followed the tutorial opencv windows 10 cuda gpu, and everything worked perfectly. but inside the build \ lib\ no python folder with pyd file , and imprt cv2 , version no attribute error message
opencv4.5.1 n python38
If you followed a third party guide I would ask the person who wrote it as they will know the operations they have instructed you to perform and the failure points which could lead to your issue.
Without seeing the guide or having any idea which operations you have performed, I would conclude that you haven’t built the python bindings. I would compare your CMake flags with the ones shown in this guide
and verify you have output similar to that shown under Example of CMake Configuration Output. e.g.
– Python 3:
– Interpreter: C:/Users/username/mambaforge/python.exe (ver 3.9.16)
– Libraries: C:/Users/username/mambaforge/libs/python39.lib (ver 3.9.16)
– numpy: C:/Users/username/mambaforge/Lib/site-packages/numpy/core/include (ver 1.23.5)
– install path: C:/Users/username/mambaforge/Lib/site-packages/cv2/python-3.9
and that python3 is included in the “To be built:” section. e.g.
– OpenCV modules:
– To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab world xfeatures2d ximgproc xobjdetect xphoto
So, I used CMake GUI with the same switchs . , Cuda, one difference i built under Anaconda env, so all paths libraries ,numpy …etc , python exe are under envs.
but by cmd line i get this - Processing WORLD modules… DONE
CMake Error at cmake/OpenCVUtils.cmake:1458 (target_link_libraries):
Syntax error in cmake code at
C:/Users/TEST/opencvinstall/opencv-4.5.1/cmake/OpenCVUtils.cmake:1458
when parsing string
PRIVATE;C:\Users\TEST\anaconda3\envs\openmmlab\libs\pythonp38.lib
Invalid character escape ‘\U’.
Call Stack (most recent call first):
cmake/OpenCVUtils.cmake:1488 (__ocv_push_target_link_libraries)
modules/python/common.cmake:49 (ocv_target_link_libraries)
modules/python/python3/CMakeLists.txt:20 (include)
– Configuring incomplete, errors occurred!
Can you post the exact command line and the all of the output you get please.
“C:\Program Files/CMake/bin/cmake.exe” -B"C:\OpenCV" -H"C:\Users/TEST/opencvinstall/opencv-4.5.1" -DOPENCV_EXTRA_MODULES_PATH=“C:\Users/TEST/opencvinstall/opencv_contrib-4.5.1/modules” -G"Visual Studio 16 2019" -DINSTALL_TESTS=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DBUILD_opencv_world=ON -DWITH_CUDA=ON -DWITH_CUBLAS=ON -DWITH_CUFFT=ON -DCUDA_ARCH_PTX=7.5 -DBUILD_opencv_python3=ON -DPYTHON3_INCLUDE_DIR=C:\Users/TEST/anaconda3/envs/openmmlab/include -DPYTHON3_LIBRARY=C:/Users/TEST/anaconda3/envs/openmmlab/libs/python38.lib -DPYTHON3_EXECUTABLE=C:\Users/TEST/anaconda3/envs/openmmlab/python.exe -DPYTHON3_NUMPY_INCLUDE_DIRS=C:\Users/TEST/anaconda3/envs/openmmlab/lib/site-packages/numpy/core/include -DPYTHON3_PACKAGES_PATH=C:\Users/TEST/anaconda3/envs/openmmlab/Lib/site-packages
It configures for me if I use standard quotes (") and not the weird ones you have (“). i.e.
"C:\Program Files/CMake/bin/cmake.exe" -B"C:\OpenCV" -H"C:\Users/TEST/opencvinstall/opencv-4.5.1" -DOPENCV_EXTRA_MODULES_PATH="C:\Users/TEST/opencvinstall/opencv_contrib-4.5.1/modules" -G"Visual Studio 16 2019" -DINSTALL_TESTS=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DBUILD_opencv_world=ON -DWITH_CUDA=ON -DWITH_CUBLAS=ON -DWITH_CUFFT=ON -DCUDA_ARCH_PTX=7.5 -DBUILD_opencv_python3=ON -DPYTHON3_INCLUDE_DIR=C:\Users/TEST/anaconda3/envs/openmmlab/include -DPYTHON3_LIBRARY=C:/Users/TEST/anaconda3/envs/openmmlab/libs/python38.lib -DPYTHON3_EXECUTABLE=C:\Users/TEST/anaconda3/envs/openmmlab/python.exe -DPYTHON3_NUMPY_INCLUDE_DIRS=C:\Users/TEST/anaconda3/envs/openmmlab/lib/site-packages/numpy/core/include -DPYTHON3_PACKAGES_PATH=C:\Users/TEST/anaconda3/envs/openmmlab/Lib/site-packages
i copy past yours , i get same error ! so i do the process by GUI no error build by visual Studio, also no errors , but no pyd
Try deleting the build folder and trying again.
big thanks , this step is ok , –
– Configuring done (103.9s)
– Generating done (75.7s)
– Build files have been written to: C:/OpenCV
C:\Users\TEST>
what is the next step?
Check step (3) from the guide I linked to.
Erreur LNK1104 impossible d’ouvrir le fichier ‘python38_d.lib’ opencv_python3 C:\OpenCV\modules\python3\LINK 1
it is in French but error Link1104
See the Important note under section (3).
big thanks , i get installed you are the best
(openmmlab) C:\Users\TEST>python
Python 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type “help”, “copyright”, “credits” or “license” for more information.
import cv2
cv2.version
‘4.5.1’