Fix OpenCV on Windows: DLL Errors, PATH, Camera Issues

Quick, practical fixes for the most common OpenCV problems on Windows 11/10. Covers Python import errors, missing MSVCP/Microsoft runtime DLLs, PATH, camera not opening, and other runtime issues.

TL;DR — Fast fixes

  1. For import errors, use a fresh virtual environment and reinstall OpenCV and numpy.
  2. If a DLL is missing, add OpenCV bin to PATH or copy the DLLs next to the executable.
  3. For camera issues, ensure correct device index and that no other app uses the camera.

If you still have problems, follow the detailed checklist below.

1) Python import errors: ImportError: DLL load failed

Symptoms: import cv2 fails with "DLL load failed" or "module not found" messages.

Checklist

  • Create a clean virtual environment (venv or conda) and activate it.
  • Run: python -m pip install --upgrade pip setuptools wheel
  • Install OpenCV and numpy inside that env: pip install opencv-contrib-python numpy
  • If using conda, consider using pip inside conda env or conda-forge packages.
  • Verify which python is used: python -c "import sys;print(sys.executable)"

2) Missing MSVC or runtime DLLs

Symptoms: errors mentioning MSVCP140.dll, VCRUNTIME140.dll, or similar.

Fixes

  • Install the latest Microsoft Visual C++ Redistributable (x64) from Microsoft official downloads.
  • Ensure the redistributable matches the MSVC version used for the OpenCV build (common recent versions cover many builds).
  • Restart your system after installation if issues persist.

3) "The program can't start because ... dll is missing" for C++

Symptoms: Running your EXE fails complaining about missing OpenCV DLLs.

Fixes

  • Add OpenCV bin directory to the System or User PATH: Control Panel → System → Advanced system settings → Environment Variables.
  • Or copy required Opencv binaries (DLLs) into the same folder as your executable.
  • Match runtime types: don't mix Debug builds with Release DLLs and ensure all libs are x64.

4) Camera not opening or strange camera errors

Symptoms: VideoCapture(0) returns empty frames or fails.

Checklist

  • Confirm camera index: try 0,1,2 etc. Multiple cameras/devices change indices.
  • Ensure another application (Teams/Zoom/Browser) is not locking the camera.
  • Check Windows camera privacy settings: Settings → Privacy & security → Camera → allow apps to access camera.
  • Test with a minimal script:
import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
    print('Camera open failed')
else:
    ret, frame = cap.read()
    print('Frame ok:', ret)
cap.release()

5) Video I/O / GStreamer / FFmpeg issues

Symptoms: imread works but VideoCapture for files or streams fails, or certain codecs are unsupported.

Notes & fixes

  • Official wheels include common FFmpeg builds but not all codec variants.
  • Use opencv-python packages that include ffmpeg support; for custom cases, build OpenCV with your desired codec support.
  • Ensure file paths do not contain non-ASCII characters — on Windows, this can cause issues with older I/O builds.

6) Permission and antivirus blocking

  • Sometimes antivirus or Windows Defender may quarantine DLLs. Check quarantine logs and exclude the OpenCV install folder if safe.
  • Run your IDE/terminal as Administrator if you encounter permission-denied issues during install.

7) If nothing helps — a final checklist

  1. Use a fresh user account or clean virtual environment.
  2. Install Microsoft Visual C++ Redistributable (x64).
  3. Ensure Python and OpenCV wheel architectures match (x64).
  4. Try the official OpenCV Windows installer to get prebuilt libraries: opencv-4.12.0-windows.exe.
  5. Search the Troubleshooting page sections for the exact error text — copy-paste the message into Google/GitHub issues.

Common error FAQs

Why does import cv2 fail with "DLL load failed"?
Usually due to mismatched or missing MSVC runtime libraries, incompatible numpy, or the wrong Python interpreter. Try a fresh venv, reinstall numpy and OpenCV, and install the Visual C++ Redistributable (x64).
Which Visual C++ Redistributable do I need?
Install the latest supported x64 Visual C++ Redistributable. Recent builds typically require the Universal CRT and MSVC runtime; download from Microsoft official site.
How to make OpenCV DLLs load at runtime?
Add the OpenCV bin folder to the System PATH or copy DLLs to the executable directory; check architecture (x64) and runtime (Release/Debug).
Camera works in other apps but not in OpenCV
Try different device indices, ensure camera permissions for apps are enabled, and close other apps that may access the camera. Test with a minimal capture script.

Related pages