Skip to content

OpenCV CMake windows build problem with PYTHON3_LIBRARY  #20206

@quickgrid

Description

@quickgrid
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.

1

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,

3

2

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
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions