Title: Installing OpenCV on Windows - PyImageSearch

URL Source: https://pyimagesearch.com/2022/04/25/installing-opencv-on-windows/

Published Time: 2022-04-25T13:00:00+00:00

Markdown Content:
* * *

Table of Contents
-----------------

*   [Installing OpenCV on Windows](#H2BlogTitle)

*   [Installing OpenCV Using Pip](#H3Install)
*   [Having Problems Configuring Your Development Environment?](#H3Have)

*   [Summary](#H2Summary)

*   [References](#H3Refs)
*   [Citation Information](#H3CitInfo)

* * *

In this tutorial, you will learn how to install OpenCV on Windows. This includes a complete guide to installation using prebuilt binaries.

![Image 1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201024%20575'%3E%3C/svg%3E)

After completing this blog post, you will be able to install OpenCV on your Windows machine on your own. You will also be able to choose the method that will suit you the best.

**To learn how to Install OpenCV on Windows, _just keep reading._**

* * *

Hello and welcome to today’s tutorial. If you are here, I assume you must have a Windows computer or need to use one for Computer Vision. First, let me assure you of a doubt you might have nurtured.

**Yes**, it is **possible to practice Deep Learning and Computer Vision** on a **Windows machine**. We at PyImageSearch are firm believers in democratizing learning.

You **do not need an expensive laptop** to get started with OpenCV.

In this tutorial, we will guide you through the various ways you can follow to get OpenCV installed on your Windows computer.

* * *

### **[Installing OpenCV Using Pip](#TOC)**

Installing OpenCV Python using pip is fairly easy. However, there are a few things to keep in mind before we get started.

1.  This is a prebuilt CPU-only OpenCV package for Python. You cannot follow these steps if you are on a GPU-powered computer.
2.  These are unofficial prebuilt packages for installing OpenCV. They are not official OpenCV packages released by the [OpenCV.org](https://opencv.org/) team.
3.  It is essential to have Python and pip installed on your Windows machine before you get started. If you do not have Python installed, please download and install the latest version from [here](https://www.python.org/downloads/).

With all the disclaimers and prerequisites done, let’s get started with some installation. Here are four OpenCV packages that are pip-installable on the PyPI repository:

*   [**opencv-python**](https://pypi.org/project/opencv-python/)**:** This repository contains **just the main modules** of the OpenCV library. If you’re a PyImageSearch reader, you do not want to install this package.
*   [**opencv-contrib-python**](https://pypi.org/project/opencv-contrib-python/)**:** The opencv-contrib-python repository contains both the **main modules along with the contrib modules**. This is the library **we recommend you install**, as it includes all OpenCV functionality.
*   [**opencv-python-headless**](https://pypi.org/project/opencv-python-headless/)**:** Same as opencv-python but no GUI functionality. Useful for headless systems.
*   [**opencv-contrib-python-headless**](https://pypi.org/project/opencv-contrib-python-headless/)**:** Same as opencv-contrib-python but no GUI functionality. Useful for headless systems.

You DO NOT want to install both opencv-python and opencv-contrib-python. Pick ONE of them.

**Step 1:** Make sure you have python and pip installed. Pip version 19.3 is the minimum supported version. This means a pip with a version higher than 19.3 is required.

To check the pip version, open your command prompt and type:

$ pip -V

This will let you know the version of pip you are using. To upgrade pip to the latest version type:

$ pip install --upgrade pip

**Step 2 (optional):** Create a virtual environment and install OpenCV there. Creating a virtual environment in Python is a very good practice, and we highly recommend it.

You can develop multiple projects without worrying if your libraries are going to crash with each other. This can be achieved through `virtualenv` and `virtualenvwrapper` as well as Anaconda. In this tutorial, we will use `virtualenv` and `virtualenvwrapper`.

$ pip install virtualenv virtualenvwrapper
$ pip install virtualenvwrapper-win

You’ll see some terminal output that sets up `virtualenvwrapper`. You now have access to new terminal commands:

*   Create an environment with `mkvirtualenv`.
*   Activate an environment (or switch to a different one) with `workon`.
*   Deactivate an environment with `deactivate`.
*   Remove an environment with `rmvirtualenv`.

[Read the documentation](https://virtualenvwrapper.readthedocs.io/en/latest/) to get familiar with the commands.

Next, create a virtual environment called `cv` (you can name it anything you want) to install OpenCV.

$ mkvirtualenv cv -p python3

Switch to this environment using:

$ workon cv

**Step 3:** With everything taken care of, we finally start installing OpenCV on your Windows system.

$ pip install opencv-contrib-python

To check if OpenCV is installed properly, open a new command prompt and enter a Python shell using the following command:

$ python 

>> import cv2
>> print(cv2.\_\_version\_\_)

And that’s it. OpenCV is successfully installed on your windows machine. You are ready to embark on your Computer Vision journey.

We recommend you go through some of our [tutorials on OpenCV](https://pyimagesearch.com/category/opencv/) fundamentals to get yourself acquainted with the topic.

* * *

### **[Having Problems Configuring Your Development Environment?](#TOC)**

[![Image 2](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20500%20334'%3E%3C/svg%3E)](https://pyimagesearch.com/pyimagesearch-university/)

**Figure 1:** Having trouble configuring your dev environment? Want access to pre-configured Jupyter Notebooks running on Google Colab? Be sure to join [PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/) — you’ll be up and running with this tutorial in a matter of minutes.

All that said, are you:

*   Short on time?
*   Learning on your employer’s administratively locked system?
*   Wanting to skip the hassle of fighting with the command line, package managers, and virtual environments?
*   **Ready to run the code** **_right now_** **on your Windows, macOS, or Linux system?**

Then join [PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/) today!

**Gain access to Jupyter Notebooks for this tutorial and other PyImageSearch guides that are** **_pre-configured_** **to run on Google Colab’s ecosystem right in your web browser!** No installation required.

And best of all, these Jupyter Notebooks will run on Windows, macOS, and Linux!

* * *

### What's next? We recommend [PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend).

**Course information:**  
84 total classes • 114+ hours of on-demand code walkthrough videos • Last updated: February 2024  
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled

**I strongly believe that if you had the right teacher you could _master_ computer vision and deep learning.**

Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?

That’s _not_ the case.

All you need to master computer vision and deep learning is for someone to explain things to you in _simple, intuitive_ terms. _And that’s exactly what I do_. My mission is to change education and how complex Artificial Intelligence topics are taught.

If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to _successfully_ and _confidently_ apply computer vision to your work, research, and projects. Join me in computer vision mastery.

**Inside PyImageSearch University you'll find:**

*   ✓ **84 courses** on essential computer vision, deep learning, and OpenCV topics
*   ✓ **84 Certificates** of Completion
*   ✓ **114+ hours** of on-demand video
*   ✓ **Brand new courses released _regularly_**, ensuring you can keep up with state-of-the-art techniques
*   ✓ **Pre-configured Jupyter Notebooks in Google Colab**
*   ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
*   ✓ Access to **centralized code repos for _all_ 536+ tutorials** on PyImageSearch
*   ✓ **Easy one-click downloads** for code, datasets, pre-trained models, etc.
*   ✓ **Access** on mobile, laptop, desktop, etc.

[Click here to join PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend)

* * *

**[Summary](#TOC)**
-------------------

In this tutorial, we learned how to install OpenCV from prebuilt binaries. We also learned which package to install and how to create a virtual environment for working on the package. For all purposes of learning computer vision using Python, we highly recommend installing opencv-contrib-python using prebuilt binaries.

If you are looking to start your development journey in computer vision, check out some of our [tutorials on OpenCV](https://pyimagesearch.com/category/opencv/).

Happy learning 🙂

* * *

### **[References](#TOC)**

1.  PyImageSearch: [Pip Install OpenCV guide](https://pyimagesearch.com/2018/09/19/pip-install-opencv/)
2.  Adam Hacks: [Installing OpenCV on Windows](https://www.youtube.com/watch?v=x5EWlNQ6z5w)
3.  PyPi: [Pip install OpenCV](https://pypi.org/project/opencv-python/)

* * *

### **[Citation Information](#TOC)**

**Raha, R.** “Installing OpenCV on Windows,” _PyImageSearch_, D. Chakraborty, P. Chugh, A. R. Gosthipaty, S. Huot, K. Kidriavsteva, and A. Thanki, 2022, [https://pyimg.co/b3q05](https://pyimg.co/b3q05)

@incollection{Raha\_2022\_Installing-OpenCV-Windows,
  author = {Ritwik Raha},
  title = {Installing {OpenCV} on {W}indows},
  Booktitle = {PyImageSearch},
  editor = {Devjyoti Chakraborty and Puneet Chugh and Aritra Roy Gosthipaty and Susan Huot and Kseniia Kidriavsteva and and Abhishek Thanki},
  year = {2022},
  note = {https://pyimg.co/b3q05},
}

* * *

![Image 3: Featured Image](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20500%20276'%3E%3C/svg%3E)

### Unleash the potential of computer vision with Roboflow - Free!

*   Step into the realm of the future by [signing up or logging into your Roboflow account](https://roboflow.com/?ref=pyimagesearch). Unlock a wealth of innovative dataset libraries and revolutionize your computer vision operations.
*   Jumpstart your journey by choosing from our broad array of datasets, or benefit from PyimageSearch’s comprehensive library, crafted to cater to a wide range of requirements.
*   Transfer your data to Roboflow in any of the 40+ compatible formats. Leverage cutting-edge model architectures for training, and deploy seamlessly across diverse platforms, including API, NVIDIA, browser, iOS, and beyond. Integrate our platform effortlessly with your applications or your favorite third-party tools.
*   Equip yourself with the ability to train a potent computer vision model in a mere afternoon. With a few images, you can import data from any source via API, annotate images using our superior cloud-hosted tool, kickstart model training with a single click, and deploy the model via a hosted API endpoint. Tailor your process by opting for a code-centric approach, leveraging our intuitive, cloud-based UI, or combining both to fit your unique needs.
*   Embark on your journey today with absolutely no credit card required. Step into the future with Roboflow.

[Join Roboflow Now](https://roboflow.com/?ref=pyimagesearch)

![Image 4](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20410%20567'%3E%3C/svg%3E)

#### Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF

Enter your email address below to **join the PyImageSearch Newsletter** and **download my FREE 17-page Resource Guide PDF** on Computer Vision, OpenCV, and Deep Learning.