Skip to content

Self compiled OpenCV Python with Gstreamer on Windows is not imported properly #871

@timorkal

Description

@timorkal

I've built OpenCV Python from source with Gstreamer support on Windows 10 machine using Mingw64.
Everything is working well in my Python Virtualenv.
Though the only thing I need to add to my main.py code before the import cv2 is:
import os
os.add_dll_directory(GSTREAMER_PATH)
Where GSTREAMER_PATH is the 'bin" directory of where the Gstreamer is installed.
Without setting these lines I get this error:
ImportError: DLL load failed while importing cv2: The specified module could not be found.

Now when I try to package everything with PyInstaller it fails on the same error:

572 WARNING: Failed to collect submodules for 'cv2' because importing 'cv2' raised: ImportError: DLL load failed while importing cv2: The specified module could not be found.

For validation. I have tried to uninstall my own compiled OpenCV and install the Pypi one "opencv-python", then the Pyinstaller manages to package it properlly.
The problem using the Pypi one is that it doesn't come with Gstreamer support, so I must use my own.

I understand that PyInstaller automatically tries to use the hook-cv2.py. But looks that it doesn't handle properly such kinds of scenarios.

My environment versions are:
OS: Windows 10 x64.
Python: 3.11.
PyInstaller: 6.12.0.
Pyinstaller-hooks-conrib: 2025.1.
OpenCV: 4.11.0.
Gstreamer: 1.24.12

Any help please with how to import cv2 properly in my scenario?

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:triageWe're still figuring out how severe this issue is

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions