Skip to content

ImportError: DLL load failed Windows Server 2016 on Python > 3.7 with CUDA prebuilt #955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dcarrion87 opened this issue Feb 15, 2024 · 3 comments

Comments

@dcarrion87
Copy link

dcarrion87 commented Feb 15, 2024

Unable to import DLL from https://github.com/cudawarped/opencv-python-cuda-wheels/releases/tag/4.9.0.80 version from @cudawarped on python > 3.7 on Windows Server 2016.

Having difficulty tracing down what's changed between python distribution between versions to determine why the import would be an issue with newer python versions on the same system.

Expected behaviour

E.g.: On Python 3.7:

C:\Users\dc>C:\Python\Python37\python.exe -m pip install C:\opencv\opencv_contrib_python-4.9.0.80-cp37-abi3-win_amd64.whl

C:\Users\dc>C:\Python\Python37\python.exe
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>

Actual behaviour

On anything greater than 3.7. For example 3.9, but it happens for any other up to 3.11:

C:\Users\dc>C:\Python\Python39\python.exe -m pip install C:\opencv\opencv_contrib_python-4.9.0.80-cp37-abi3-win_amd64.whl

C:\Users\dc>C:\Python\Python39\python
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python\Python39\lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Python\Python39\lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "C:\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing cv2: The specified module could not be found.

Steps to reproduce

Notes

dumpbin /dependents cv2.pyd
Microsoft (R) COFF/PE Dumper Version 14.29.30154.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file cv2.pyd

File Type: DLL

  Image has the following dependencies:

    python3.dll
    WSOCK32.dll
    ole32.dll
    USER32.dll
    GDI32.dll
    nvcuda.dll
    nvcuvid.dll
    nvEncodeAPI64.dll
    nppc64_12.dll
    nppial64_12.dll
    nppicc64_12.dll
    nppidei64_12.dll
    nppif64_12.dll
    nppig64_12.dll
    nppim64_12.dll
    nppist64_12.dll
    nppitc64_12.dll
    cublas64_12.dll
    cudnn64_8.dll
    cufft64_11.dll
    KERNEL32.dll
    OLEAUT32.dll
    COMDLG32.dll
    ADVAPI32.dll
    MFPlat.DLL
    MF.dll
    MFReadWrite.dll
    dxgi.dll
    d3d11.dll
    SHLWAPI.dll
@opencv-alalek
Copy link

Blame on Python team - they broke many things with Python 3.8 on Windows and PATH could not help anymore: opencv/opencv#16120


config.py of mentioned wheel has these lines:

import os

BINARIES_PATHS = [
    ...
    os.path.join(os.getenv('CUDA_PATH', 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3'), 'bin')
] + BINARIES_PATHS

Dump os.getenv('CUDA_PATH') before import cv2. If it is not set, then specify it.

If it is not enough then propose patch to upstream similar to https://github.com/opencv/opencv/pull/16503/files

@dcarrion87
Copy link
Author

dcarrion87 commented Feb 15, 2024

@opencv-alalek bingo. For anyone that needs it:

https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew

If you need the old Path behaviour efore you import cv2:

import os
os.environ["PATH"] = os.getenv('PATH') 
paths = os.getenv('PATH').split(";")
for path in paths:
    try:
        os.add_dll_directory(path)
    except Exception as e:
        print(e)

@cudawarped
Copy link

That approach maybe a bit heavy handed (or maybe not). As mentioned by @opencv-alalek if the missing dll is from the CUDA toolkit which is imported by config.py then you may have an incorrectly set CUDA_PATH or your installation of the CUDA toolkit is not in C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants