OpenCV on Windows with Python (pip, venv, Anaconda)

Install OpenCV 4.12.0 for Python on Windows 11/10. Learn which package to pick (opencv-python, headless, or contrib), how to isolate environments, and how to avoid common pitfalls.

  • Requirements: Windows 11/10 x64, Python 3.8+
  • Recommended: Virtual environments (venv or conda)
  • Editor support: VS Code, PyCharm, or your preferred IDE

TL;DR — Python quick steps

  1. Create a virtual environment (venv/conda).
  2. Install the package you need (opencv-python / opencv-contrib-python / opencv-python-headless).
  3. Verify import and version.

Need GPU or C++? See CUDA and C++.

Pick the right Python package

  • opencv-python — standard wheels with GUI and video I/O; good default for desktops.
  • opencv-contrib-python — includes extra modules (contrib) such as xfeatures2d; slightly larger.
  • opencv-python-headless — no GUI; ideal for servers/CI where you don't need highgui/video modules.

When to pick each

  • Desktop apps, camera/video preview → opencv-python.
  • Need SIFT/SURF-like features or contrib modules → opencv-contrib-python.
  • Server/CI or no display/audio → opencv-python-headless.

Virtual environments (recommended)

Keep your global Python clean and avoid conflicts by using isolated environments.

venv (built-in)

  1. Create a new venv in your project folder.
  2. Activate it in your terminal.
  3. Install the desired OpenCV package.

Conda (Anaconda/Miniconda)

  1. Create a new conda environment with your target Python version.
  2. Install via pip inside conda or try conda-forge if available.
  3. Verify versions of numpy and OpenCV are compatible.

Common Windows pitfalls

  • Conflicting numpy: update numpy before installing OpenCV if you see import errors.
  • Multiple Python installations: ensure your IDE uses the same interpreter where you installed OpenCV.
  • Camera not opening: close other apps using the webcam and test with a simple capture script.
  • 32-bit vs 64-bit: use 64-bit Python on 64-bit Windows.

Python FAQ on Windows

Which OpenCV Python package should I choose?
Use opencv-python for most desktop cases, opencv-contrib-python for extra contrib modules, and opencv-python-headless for servers without GUI.
Do I need Microsoft C++ Build Tools?
No for prebuilt wheels from PyPI (pip). You may need them only when building from source.
Will this work with Windows 11 and Windows 10?
Yes, on 64-bit systems with a supported Python version (3.8+ recommended).
ImportError: DLL load failed or numpy mismatch?
Update numpy and reinstall OpenCV inside a fresh virtual environment. See Troubleshooting.

Related pages