I have a “similar”, but not same problem. I have compiled OpenCV 4.10.0 with:
Visual Studio 2022
CUDA 12.5.0
CuDNN 9.1.1
Contrib 4.X
Python 3.12.3
Compilation was succesfull, all DLL are generated, and also a cv2 folder in site-package of Python 3.12 instalation has been generated.
There are a config-3.11.py file (I have copied also renamed to 3.12.py to try to resolve the issue). Also edited the file and changed python-3.11 to python-3.12.
Also duplicated the python-3.11 folder with 3.12, both with the file cv2.cp312-win_amd64.pyd inside.
But in any case, I can’t import cv2 on python with this error:
import cv2 as cv
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\cv2_init_.py”, line 181, in
bootstrap()
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\cv2_init_.py”, line 153, in bootstrap
native_module = importlib.import_module(“cv2”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\AVIAitex\AppData\Local\Programs\Python\Python312\Lib\importlib_init_.py”, line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing cv2: No se puede encontrar el módulo especificado.
I don’t know with DLL file is missing, the opencv_world4100.dll are on path, and OpenCV C++ compiled samples work withyout problem (also tried to copy them to the site-packages folder), but always with this problem.
Anybody knows what is the problem?
Thanks in advance.
I post in new thread, as the other is a little old and not the same issue:
I have compiled OpenCV 4.10.0 to use with C++ and Python under Windows with:
Visual Studio 2022
CUDA 12.5.0
CuDNN 9.1.1
Contrib 4.X
Python 3.12.3
Compilation was succesfull, all DLL are generated, and also a cv2 folder in site-package of Python 3.12 instalation has been generated.
There are a config-3.11.py file (I have copied also renamed to 3.12.py to try to resolve the issue). Also edited the file and changed python-3.11 to python-3.12.
Also duplicated the python-3.11 folder with 3.12, both with the file cv2.cp312-win_amd64.pyd inside.
But in any case, I can’t import cv2 on python with this error:
import cv2 as cv
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\cv2_init.py”, line 181, in
bootstrap()
File “C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\cv2init.py”, line 153, in bootstrap
native_module = importlib.import_module(“cv2”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\AVIAitex\AppData\Local\Programs\Python\Python312\Lib\importlibinit_.py”, line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing cv2: No se puede encontrar el módulo especificado.
I don’t know with DLL file is missing, the opencv_world4100.dll are on path, and OpenCV C++ compiled samples work withyout problem (also tried to copy them to the site-packages folder), but always with this problem.
Anybody knows what is the problem?
Thanks in advance.
If you remove/rename the cv2 folder and then build the install again (this should only copy the install files) do you still get files/folders referencing python 3.11 when you are building against 3.12? Also what is your CMake python output? e.g.
Well, thanks in advance for the response. I am trying to fix using your help.
The path on config.py is correct, and I have to use the process monitor to see what is happening. The missing dll is Python311.dll!
The CMake Python output looks strange:
I have also installed Python 3.11, but not any reference to it, and removed from PATH, so I can’t imagine why it points to Python 3.11 at this point. Any suggestion?
Thanks in advance.
Ruben
PD: I have just completly uninstalled 3.11, and go to rebuild OpenCV to see what happens now.
I would guess something has gone wrong during CMake configuration, maybe you changed a parameter and then configured again and it didn’t work. Definitely the libraries path is wrong and is the reason for your issue.
I would always advise using the command line for CMake and not the GUI for OpenCV because
You can provide the input args when asking a question
It doesn’t suffer as badly from re-configuration issues.
Either way you need to clean your build directory and start again.
Finally I managed it working. I have totally uninstalled Python 3.11 and deleted directory, and begin from 0 the Build (clearing cache on CMake GUI doesn’t work, issues with 3.11 still apears, and I can’t manage CMake without GUI).
After that I still get error on import cv2, but using the process monitor I found that now was missing cudnn64_9.dll (although it was on PATH). So with your tip adding to config.py, now all works correctly.