System information (version)
- OpenCV => 4.5.2
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2019
Detailed description
I am trying compile opencv for python 3.9 in conda. Initially got no module named cv2 error after copying cv2.cp39-win_amd64.pyd file to Lib/site-packages. Then tried visual studio cmake install target that gave ImportError: DLL load failed while importing cv2: The specified module could not be found. error.
I have unticked BUILD_SHARED_LIBS, ticked BUILD_opencv_world and set CMAKE_CONFIGURATION_TYPES to RELEASE only. Also set path for opencv-contrib via OPENCV_EXTRA_MODULES_PATH to opencv-contrib source modules folder. Ticked WITH_CUDA, OPENCV_DNN_CUDA, set CUDA_ARCH_BIN value based for my GPU. If the cuda part is not used then copying the pyd file to site-packages worked. In this case, I modified CMakeCache.txt to replace all python 3.7 path to correct conda env path.

Now I am noticing no matter what I set in PYTHON3_LIBRARY it is not showing up in configure output. I have tried CMake 3.18 and 3.20.3. I clicked configure multiple times after changing the path but remains same. After clicking configure first time, PYTHON3_LIBRARY is set to C:/Users/computer/miniconda3/libs/python37.lib and does not change anymore. Pointing the path to another env python37.lib does not help. Deleting cmake cache and reconfiguring, using another folder does not help.
This is cv2 folder in under Lib/site-packages/ does not have config for python 3.9 after install. Doing an install with Visual Studio CMakeTargets installs like this,


Steps to reproduce
Have anaconda/miniconda with multiple environments and python 3.9 with numpy. Try to set PYTHON3_LIBRARY to different path in cmake configure.
Issue submission checklist
System information (version)
Detailed description
I am trying compile opencv for python 3.9 in conda. Initially got
no module named cv2error after copyingcv2.cp39-win_amd64.pydfile toLib/site-packages. Then tried visual studio cmake install target that gaveImportError: DLL load failed while importing cv2: The specified module could not be found.error.I have unticked
BUILD_SHARED_LIBS, tickedBUILD_opencv_worldand setCMAKE_CONFIGURATION_TYPEStoRELEASEonly. Also set path for opencv-contrib viaOPENCV_EXTRA_MODULES_PATHto opencv-contrib source modules folder. TickedWITH_CUDA,OPENCV_DNN_CUDA, setCUDA_ARCH_BINvalue based for my GPU. If the cuda part is not used then copying the pyd file to site-packages worked. In this case, I modifiedCMakeCache.txtto replace all python 3.7 path to correct conda env path.Now I am noticing no matter what I set in
PYTHON3_LIBRARYit is not showing up in configure output. I have tried CMake3.18and3.20.3. I clicked configure multiple times after changing the path but remains same. After clicking configure first time,PYTHON3_LIBRARYis set toC:/Users/computer/miniconda3/libs/python37.liband does not change anymore. Pointing the path to another envpython37.libdoes not help. Deleting cmake cache and reconfiguring, using another folder does not help.This is
cv2folder in underLib/site-packages/does not have config for python 3.9 after install. Doing an install with Visual StudioCMakeTargetsinstalls like this,Steps to reproduce
Have anaconda/miniconda with multiple environments and python 3.9 with numpy. Try to set
PYTHON3_LIBRARYto different path in cmake configure.Issue submission checklist
forum.opencv.org, Stack Overflow, etc and have not found solution