# Import not possible after build OpenCV with CUDA in Windows 10 (Python3.9)

**URL:** <https://forum.opencv.org/t/import-not-possible-after-build-opencv-with-cuda-in-windows-10-python3-9/10693>\
**Category:** Python\
**Tags:** windows, build, cuda\
**Created:** [October 26, 2022, 3:33pm UTC](https://forum.opencv.org/t/import-not-possible-after-build-opencv-with-cuda-in-windows-10-python3-9/10693 "2022-10-26T15:33:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![petop](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@petop](https://forum.opencv.org/u/petop)\
**Post date:** [October 26, 2022, 3:33pm UTC](https://forum.opencv.org/t/import-not-possible-after-build-opencv-with-cuda-in-windows-10-python3-9/10693/1 "2022-10-26T15:33:35Z")

</div>

Hello all,

I have been looking for a solution for several days and could not find one for the following error:

> Blockquote  
> Traceback (most recent call last):  
> File “\<pyshell#0\>”, line 1, in   
> import cv2  
> File “C:\Python\lib\site-packages\cv2\__init_\_.py”, line 181, in   
> bootstrap()  
> File “C:\Python\lib\site-packages\cv2\__init_\_.py”, line 153, in bootstrap  
> native\_module = importlib.import\_module(“cv2”)  
> File “C:\Python\lib\importlib\__init_\_.py”, line 127, in import\_module  
> return \_bootstrap.\_gcd\_import(name[level:], package, level)  
> ImportError: DLL load failed while importing cv2: Das angegebene Modul wurde nicht gefunden. \<

I can’t figure out what is causing this.  
If I install this via PIP, opencv works without problems, only then without CUDA. What I would like to change.  
When creating everything went through without problems, even with cmake.  
Therefore, I am now at the end where I should still look for the error.  
Does anyone have tips on what you could check everything?  
Or even a solution for?

THANKS FOR ANY HELP!

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [October 27, 2022, 4:10pm UTC](https://forum.opencv.org/t/import-not-possible-after-build-opencv-with-cuda-in-windows-10-python3-9/10693/2 "2022-10-27T16:10:19Z")

</div>

I think you have to give path to cuda dll. Something like this in **init**.py :

```auto
'''
OpenCV Python binary extension loader
'''
import os
import sys
os.add_dll_directory(r'G:\Lib\install\opencv\x64\vc15\bin')
os.add_dll_directory(r'G:\Lib\install\vtk\bin')
os.add_dll_directory(r'G:\Lib\install\ceres-solver\bin')
os.add_dll_directory(r'G:\Lib\install\glog\bin')
os.add_dll_directory(r'F:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin')
os.add_dll_directory(r'F:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2')

try:
    import numpy
    import numpy.core.multiarray
except ImportError:
    print('OpenCV bindings requires "numpy" package.')
    print('Install it via command:')
    print(' pip install numpy')
    raise

```

---

<div class="post-metadata">

**Author:** ![petop](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@petop](https://forum.opencv.org/u/petop)\
**Post date:** [October 28, 2022, 7:59am UTC](https://forum.opencv.org/t/import-not-possible-after-build-opencv-with-cuda-in-windows-10-python3-9/10693/3 "2022-10-28T07:59:19Z")

</div>

Hello,  
thanks for the tip, unfortunately did not help to solve the problem.

Can you see somewhere more precisely which DLL is missing?

Peter

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [October 28, 2022, 8:18am UTC](https://forum.opencv.org/t/import-not-possible-after-build-opencv-with-cuda-in-windows-10-python3-9/10693/4 "2022-10-28T08:18:15Z")

</div>

Did you modify the code from @laurent.berger to point to your Nvidia SDK installation and your intsall location. e.g. for me the below works

> os.add\_dll\_directory(‘D:/build/opencv/cuda\_build/bin’)  
> os.add\_dll\_directory(‘C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/bin’)

If that doesn’t work then you can track down the dll using [process monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon) by filtering for

> Process Name = python.exe  
> Operation = Create File

and looking for the dll which eventually fails. But if you are not familiar with the tool its better to verify the paths above first in case that works.

Alternatively if you are using CUDA 11.7 you could try installing this [pre-built wheel](https://github.com/cudawarped/opencv-python-cuda-wheels/releases/tag/4.6.0.20220923) after first making sure you have uninstalled all existing OpenCV wheels and deleted all files copied accross to Lib/site-packages (cv2 folder) when you built/installed OpenCv from source.

---

<div class="post-metadata">

**Author:** ![petop](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@petop](https://forum.opencv.org/u/petop)\
**Post date:** [October 28, 2022, 9:17am UTC](https://forum.opencv.org/t/import-not-possible-after-build-opencv-with-cuda-in-windows-10-python3-9/10693/5 "2022-10-28T09:17:54Z")

</div>

OMG!!! THANKS!!!

With the Process Monitor I was able to find the missing dll. It was the CUDNN file that was missing, so nothing worked for me. Copied all DLL’s where there was a problem into the CV2 folder under site-packgase and the last DLL then brought the solution.

THANK YOU VERY MUCH!!!
