Fix error

Fix opencv_iconv.dll WinError 126 on Windows — DLL load failed fix

The most common OpenCV error on Windows: DLL load failed while importing cv2: WinError 126. Fix by installing Visual C++ Redistributable, checking Python architecture and removing conflicting packages.

What this error looks like

Python
ImportError: DLL load failed while importing cv2: The specified module could not be found.
ImportError: DLL load failed while importing cv2: WinError 126
OSError: [WinError 126] The specified module could not be found
C:\Python311\Lib\site-packages\cv2\cv2.pyd

When this error includes opencv_iconv.dll or cv2.pyd in the message, it means Windows cannot load a required DLL that OpenCV depends on. The most common cause is a missing or incompatible Visual C++ Redistributable.

Install Visual C++ Redistributable

OpenCV requires the Microsoft Visual C++ Redistributable to be installed. Download and install vc_redist.x64.exe for 64-bit Python:

  • 1

    Download vc_redist.x64.exe

    Get it from aka.ms/vs/17/release/vc_redist.x64.exe (Visual Studio 2022 redistributable).

  • 2

    Run the installer

    Double-click vc_redist.x64.exe and click Install. If it says "already installed", click Repair.

  • 3

    Reinstall OpenCV

    cmd.exe
    C:\> pip uninstall opencv-python -y
    C:\> pip install opencv-python --force-reinstall
  • 4

    Test the import

    Python
    >>> import cv2
    >>> print(cv2.__version__)
    4.12.0

Architecture mismatch (32-bit vs 64-bit)

OpenCV pip wheels are 64-bit only. If you have 32-bit Python, you will get this error with no fix other than switching to 64-bit Python.

cmd.exe
# Check Python architecture:
C:\> python -c "import struct; print(struct.calcsize('P')*8, 'bit')"
64 bit
# Must show 64 bit for opencv-python to work
If this shows 32 bit, download and install Python 64-bit from python.org.

Wrong or conflicting OpenCV packages

If you have both opencv-python and opencv-contrib-python installed, they conflict. Remove all and reinstall one:

cmd.exe
# Remove all OpenCV packages:
C:\> pip uninstall opencv-python opencv-contrib-python opencv-python-headless opencv-contrib-python-headless -y
# Reinstall the one you need:
C:\> pip install opencv-python

Use Dependencies tool to find the missing DLL

For advanced diagnosis, use the free Dependencies tool to see exactly which DLL is missing:

  • Download Dependencies from GitHub
  • Open the tool and drag your cv2.pyd file into it (find it in site-packages/cv2/)
  • Look for red entries — these are the missing DLLs
  • Install the package that provides each missing DLL (usually VC++ Redistributable or CUDA runtime)

DLL error questions

VC++ Redistributable is already installed but error persists
Try repairing it: run vc_redist.x64.exe again and choose Repair. Then restart your PC and reinstall OpenCV. Sometimes the runtime needs a fresh copy even if it appears installed.
Error only in PyCharm or VS Code, not in Command Prompt
Your IDE is using a different Python interpreter than the one in your terminal. Check the IDE settings and make sure it points to the same Python where you installed OpenCV. In VS Code: Ctrl+Shift+P → "Python: Select Interpreter".
After Windows update the error came back
Windows updates can remove or replace Visual C++ Redistributables. Reinstall vc_redist.x64.exe and then pip install opencv-python --force-reinstall.

Other import errors?

Full troubleshooting guide for all OpenCV errors on Windows.

Troubleshooting guide