Skip to content

should add cuda dll path via os.add_dll_directory on windows #16500

Closed

Description

@cyyever
System information (version)
  • OpenCV => master
  • Operating System / Platform =>win10
  • Compiler => vs2019
  • CUDA 10.2
  • Python 3.8
Detailed description

I compiled opencv from source with cuda and python supports and encountered "import cv2 ,dll failed to load " error, after spent a lot of time solving this problem, I found that dll loading policy has changed in python3.8 such that PATH and the current working directory are no longer used.
Please see this note

Steps to reproduce
  1. Compiler opencv under python3.8 on windows.
  2. Can't load cv2 even when C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin is in PATH
  3. Copy all cuda DLL to C:\Python38 then it works, which shows that python3.8 doesn't use PATH when loading DLLs.
  4. Now remove all cuda DLLs from C:\Python38 and add C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin via os.add_dll_directory in cv2/init.py ,then it will work too.

Activity

  1. alalek commented on Feb 4, 2020

    @alalek
    Member

    It is Python 3.8 specific (on Windows).
    There is no good robust way to resolve broken DLLs loading.
    Some hacks are possible - see #16120 (through "loader"). You may try to add something for CUDA too.

  2. cyyever commented on Feb 4, 2020

    @cyyever
    ContributorAuthor

    It is Python 3.8 specific (on Windows).
    There is no good robust way to resolve broken DLLs loading.
    Some hacks are possible - see #16120 (through "loader"). You may try to add something for CUDA too.

    So could we use cmake commands to add cuda path to BINARIES_PATHS when cuda is enabled?

  3. cyyever commented on Feb 4, 2020

    @cyyever
    ContributorAuthor

    It is Python 3.8 specific (on Windows).
    There is no good robust way to resolve broken DLLs loading.
    Some hacks are possible - see #16120 (through "loader"). You may try to add something for CUDA too.

    I has committed a PR.

  4. added a commit that references this issue on Feb 22, 2020
    ac57455
  5. added a commit that references this issue on Jul 30, 2026
    c1e3a9e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions