How to install OpenCV on Windows

OpenCV on Windows is usually installed for Python projects that need image processing, camera access, or quick computer-vision experiments. Keeping it inside a project virtual environment prevents the cv2 package and its NumPy dependency from mixing with other Python projects on the same PC.

The Python install manager provides the py launcher on current Windows systems, and pip installs the opencv-python wheel from PyPI into the virtual environment. That wheel contains the OpenCV runtime used by import cv2, so ordinary Python work does not require a source build or Visual Studio.

Use only one OpenCV wheel family in the same environment. Choose opencv-python for standard desktop scripts, switch to opencv-contrib-python when a project needs contrib modules, and use a headless wheel only for code that does not call cv2.imshow or other HighGUI windows.

Steps to install OpenCV on Windows for Python:

  1. Open PowerShell.
  2. Install the Python install manager if the py command is missing.
    PS> winget install 9NQ7512CXL7T --accept-package-agreements --accept-source-agreements --silent
    Found Python Install Manager [9NQ7512CXL7T] Version Unknown
    Starting package install...
    Successfully installed

    Skip this step when py --version already reports Python. Reopen PowerShell after installing so the launcher aliases are loaded.

  3. Check the Python runtime selected by py.
    PS> py --version
    Python 3.14.6

    On a fresh Python install manager setup, the first launch can download the default CPython runtime before printing the version.

  4. Create a project directory.
    PS> mkdir $env:USERPROFILE\opencv-demo -Force
  5. Enter the project directory.
    PS> cd $env:USERPROFILE\opencv-demo
  6. Create a virtual environment.
    PS> py -m venv .venv
  7. Refresh pip inside the virtual environment.
    PS> .\.venv\Scripts\python.exe -m pip install --upgrade pip
    Requirement already satisfied: pip in .\.venv\Lib\site-packages (26.1.2)

    The virtual environment's Python executable is used directly, so PowerShell execution policy does not need to allow Activate.ps1.

  8. Install the standard OpenCV Python wheel.
    PS> .\.venv\Scripts\python.exe -m pip install opencv-python
    Collecting opencv-python
    ##### snipped #####
    Successfully installed numpy-2.5.0 opencv-python-4.13.0.92

    Install opencv-contrib-python instead only when a project needs contrib modules. Do not install multiple OpenCV wheel packages in the same virtual environment.

  9. Confirm that Python can import cv2.
    PS> .\.venv\Scripts\python.exe -c "import cv2; print(cv2.__version__)"
    4.13.0

    If cv2 fails with ImportError: DLL load failed, install the Microsoft Visual C++ redistributable. Windows N, Windows KN, and Windows Server may also need Microsoft media components before cv2 can load video or GUI DLLs.

  10. Create a smoke-test script.
    PS> @'
    import cv2
    import numpy as np
    
    image = np.zeros((120, 160, 3), dtype=np.uint8)
    image[:, :80] = (0, 128, 255)
    image[:, 80:] = (0, 255, 0)
    cv2.imwrite("opencv-smoke.png", image)
    
    loaded = cv2.imread("opencv-smoke.png")
    print(loaded.shape)
    '@ | Set-Content smoke-test.py
  11. Run the smoke-test script.
    PS> .\.venv\Scripts\python.exe .\smoke-test.py
    (120, 160, 3)

    The shape confirms that OpenCV wrote the PNG file and read it back as a 120 by 160 pixel, three-channel image.
    Related: How to read and write an image with OpenCV

  12. Remove the smoke-test files.
    PS> Remove-Item .\smoke-test.py, .\opencv-smoke.png