Fix error

Fix OpenCV on Windows — DLL errors, PATH & import fixes

The most common OpenCV errors on Windows with exact fixes: DLL load failed WinError 126, opencv_iconv.dll missing, opencv_world.dll not found, ModuleNotFoundError and camera issues.

Start by identifying your exact error message. The most common OpenCV errors on Windows are DLL load failures, PATH issues and import errors. Each has a specific fix.

DLL load failed errors (Python)

ImportError: DLL load failed while importing cv2: WinError 126
Missing Visual C++ Redistributable or corrupt OpenCV install
pip install opencv-python --force-reinstall
opencv_iconv.dll — WinError 126: The specified module could not be found
VC++ Redistributable not installed or wrong Python architecture
Install vc_redist.x64.exe from microsoft.com
DLL load failed: %1 is not a valid Win32 application
32-bit Python with 64-bit OpenCV (or vice versa)
Match Python and OpenCV architecture (both x64)

Full fix steps: opencv_iconv.dll error guide

DLL not found errors (C++)

opencv_world4120.dll was not found
OpenCV bin directory not in system PATH
Add C:\\opencv\\build\\x64\\vc16\\bin to PATH
opencv_ocl246.dll — The specified module could not be found
OpenCL runtime missing or outdated GPU driver
Update GPU drivers or disable OpenCL in build
AVIF.dll — LNK1107: invalid or corrupt file
Linking wrong lib file (Debug vs Release mismatch)
Use opencv_world4120.lib (Release) or opencv_world4120d.lib (Debug)

Full fix: opencv_world.dll not found guide

Python import errors

ModuleNotFoundError: No module named 'cv2'
OpenCV not installed in the active Python environment
pip install opencv-python
ImportError: cannot import name 'cv2' from partially initialized module
Circular import or name conflict with a local file called cv2.py
Delete or rename any local file called cv2.py

Full fix: import cv2 error guide

VideoCapture and camera problems

cv2.VideoCapture(0) returns False / camera does not open
Wrong backend, camera index or permission
Try cv2.VideoCapture(0, cv2.CAP_DSHOW)
Camera opens but frames are black or corrupted
DirectShow driver issue or wrong resolution
Set cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) explicitly

Full guide: VideoCapture issues guide

Diagnose your OpenCV installation

Python
# Check OpenCV version and build info:
import cv2
print(cv2.__version__)
print(cv2.getBuildInformation())
# Check which Python and pip are active:
cmd.exe
C:\> python --version
C:\> where python
C:\> pip show opencv-python

More troubleshooting questions

OpenCV installed but works in one Python and not another
You have multiple Python installations (Python 3.10, 3.11, Anaconda, etc.). OpenCV is only installed in one of them. Use where python to see all Python installations. Install OpenCV in the correct one using python -m pip install opencv-python with the full path to the Python you want.
After Windows update, OpenCV DLL errors appeared
Windows updates sometimes remove or replace Visual C++ Redistributables. Reinstall vc_redist.x64.exe from microsoft.com and then pip install opencv-python --force-reinstall.
cv2.imshow() crashes Python immediately
This usually means a Qt or OpenGL conflict. Try: import os; os.environ["QT_QPA_PLATFORM"] = "windows" before importing cv2. Or use opencv-python-headless and save images with cv2.imwrite() instead.

Specific DLL error?

Step-by-step fix for opencv_iconv.dll WinError 126.

opencv_iconv.dll fix