0

I got stuck with this error while building OpenCV from source with GStreamer features. Here is the error:

Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 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:\Program Files\Python38\lib\site-packages\cv2\__init__.py", line 102, in <module>
 bootstrap()
File "C:\Program Files\Python38\lib\site-packages\cv2\__init__.py", line 90, in bootstrap
 import cv2
ImportError: DLL load failed while importing cv2: Belirtilen modül bulunamadı.
>>>

My setup is:
Gstreamer 1.18.2 (I tried both MinGW 64-bit and MSVC 64-bit same results)
Python 3.8
OpenCV 4.5.1

What I have done so far:

  1. I change init.py file which is loading module to DEBUG mode and here is what I found:
>>> import cv2
OpenCV loader: os.name="nt"  platform.system()="Windows"
OpenCV loader: loading config: C:\Program Files\Python38\lib\site-packages\cv2\config.py
OpenCV loader: loading config: C:\Program Files\Python38\lib\site-packages\cv2\config-3.8.py
OpenCV loader: PYTHON_EXTENSIONS_PATHS=['C:/Program Files/Python38/Lib/site-packages/cv2\\python-3.8']
OpenCV loader: BINARIES_PATHS=['D:/build6/install\\x64/vc16/bin']
OpenCV loader: PATH=D:/build6/install\x64/vc16/bin;C:\Program Files\Python38\Scripts\;C:\Program Files\Python38\;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\libnvvp;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\PuTTY\;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.2.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\CMake\bin;C:\gstreamer\1.0\mingw_x86_64\bin;C:\gstreamer\1.0\mingw_x86_64\lib;C:\gstreamer\1.0\mingw_x86_64\lib\gstreamer-1.0;D:\build6\install\x64\vc16\staticlib;D:\build6\install\x64\vc16\bin;C:\Users\searo\AppData\Local\Microsoft\WindowsApps;C:\Users\searo\AppData\Local\Programs\Microsoft VS Code\bin;C:\gstreamer\1.0\mingw_x86_64\bin;C:\gstreamer\1.0\mingw_x86_64\lib;C:\gstreamer\1.0\mingw_x86_64\lib\gstreamer-1.0;D:\build6\install\x64\vc16\bin;D:\build6\install\x64\vc16\staticlib;C:\Windows\system32;
OpenCV loader: replacing cv2 module
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python38\lib\site-packages\cv2\__init__.py", line 102, in <module>
    bootstrap()
  File "C:\Program Files\Python38\lib\site-packages\cv2\__init__.py", line 90, in bootstrap
    import cv2
ImportError: DLL load failed while importing cv2: Belirtilen modül bulunamadı.
  1. I am thinking it is path issue because I opened the cv2.cp38-win_amd64.pyd file with Dependency Walker to find which DLLs missing and I found that many DLLs which looks like missing are in the System32 folder. Missing DLLs
  2. Since that I am thinking it is a path issue my paths are looking fine. And when I build OpenCV without GStreamer features it is working totally correct. Even when I build OpenCV with extra contrib modules and CUDA. My variables for both user and system:

System PATHs
System and Enviroment Variables
User PATHs

I couldn't solve this for weeks. I found another solution today but I really want OpenCV to work with GStreamer. I would be glad if someone can solve.

  • I actually just spent 3 days fixing this. Turns out I needed to use `os.add_dll_directory` for the `opencv` dlls, with `/` symbol not `\` (despite it being windows, it was very finicky for me). It's a `3.8` thing – M Z Jan 09 '21 at 19:42
  • Missing System32 DLLs are fine. That's a result of Windows always changing their DLL names, Windows will handle it fine – M Z Jan 09 '21 at 19:43

0 Answers0