Install OpenCV in Python

Install OpenCV in Python

The opencv library has many tools and functionalities to perform Computer Vision tasks associated with machine learning techniques. The library was developed for Python, C++, and Java.

We can easily read and process images and videos efficiently with this library. This tutorial will demonstrate how to install the opencv library in Python.

Install OpenCV in Python

Python, by default, provides the pip package manager. This command is used to install, update, and remove packages.

We can use this command via the command prompt. We can use this command to install Python’s opencv library.

pip install opencv-python

The above command installs the latest version of opencv on the current environment. We can also install a specific version of this library by specifying it in the above command.

For example:

pip install opencv-python==

The opencv-contrib library also contains some extra modules not available in the opencv library. These extra modules are usually in the development phase and may not have a stable API.

We can install this library using the same pip command.

pip install opencv-contrib-python

Two more options exist for the opencv library. These are the headless versions of the opencv and opencv-contrib that do not have any graphic interface and are used in Docker, Cloud, etc.

Note that we can install only one option of the opencv library in a given environment because they all share the same namespace, cv2, and can lead to fatal errors.

Author: Manav Narula
Manav Narula avatar Manav Narula avatar

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.


Related Article - Python OpenCV

  • Image Masking in OpenCV
  • Use OpenCV Library to Draw a Circle
  • Utilize Bitwise_AND on an Image Using OpenCV
  • OpenCV Package Configuration
  • OpenCV ArUco Markers
  • SIFT Using OpenCV in Python