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.
Related: How to install OpenCV on macOS
Related: How to install OpenCV on Ubuntu
Steps to install OpenCV on Windows for Python:
- Open PowerShell.
- 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.
- 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.
- Create a project directory.
PS> mkdir $env:USERPROFILE\opencv-demo -Force
- Enter the project directory.
PS> cd $env:USERPROFILE\opencv-demo
- Create a virtual environment.
PS> py -m venv .venv
- 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.
- 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.
- 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.
- 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 - 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 - Remove the smoke-test files.
PS> Remove-Item .\smoke-test.py, .\opencv-smoke.png
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.