Install OpenCV Using Conda in Python

Install OpenCV Using Conda in Python

  1. Use the conda Command to Install opencv for Anaconda
  2. Use the pip Command to Install opencv for Anaconda
  3. Use the Anaconda Navigator to Install opencv for Anaconda
  4. Use the cv2.pyd File to Install opencv for Anaconda
  5. Conclusion

Anaconda is one of the most used IDEs in Python. It has become the first choice for many data scientists who intend to work with Python due to its simplicity and robust features.

Anaconda Navigator has its commands and GUI available to manage its packages.

In Python, we can perform Computer Vision tasks related to machine learning or deep learning using several libraries.

The opencv library is one of the standard libraries available for processing images and videos in Python. This library was built for cross-platform languages and is loaded with features.

This tutorial will demonstrate how to install opencv for Anaconda Python.

Use the conda Command to Install opencv for Anaconda

Anaconda provides the Anaconda Prompt application that can be used to run command line prompts for other applications of Anaconda.

In Anaconda, the conda command exists to manage different packages for Python. We can use this command to install and manage Python libraries.

We can use the following commands in the Anaconda Prompt to install the opencv library.

conda install -c conda-forge opencv
conda install -c conda-forge/label/gcc7 opencv
conda install -c conda-forge/label/broken opencv
conda install -c conda-forge/label/cf201901 opencv
conda install -c conda-forge/label/cf202003 opencv

Any of the above commands can be used to install the opencv library. The conda-forge is a special GitHub repository maintained by some providers containing various libraries unavailable in the official distribution.

Since some versions of the opencv library are not available in the official distribution, we install it using the conda-forge.

Ubuntu users can also use the following command.

conda install --channel https://conda.anaconda.org/menpo opencv3

Use the pip Command to Install opencv for Anaconda

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

We can use the pip command to install opencv for Anaconda.

The following command can be used in the command prompt.

pip install opencv-python

The above command will install the opencv library. Note that it should be installed in the environment used in Anaconda.

We can also run this command in the Anaconda Prompt.

Use the Anaconda Navigator to Install opencv for Anaconda

The Anaconda Navigator is a GUI interface for different applications of the Anaconda distribution. We can install and manage packages using this interface.

We need to redirect to the Environments tab in the Navigator. We need to change the Installed option to Not Installed from the dropdown.

Then we get a list of packages that are not installed in the selected environment. We can search for opencv and install it if any versions of the same are shown in the default channel.

Use the cv2.pyd File to Install opencv for Anaconda

We can install opencv in Anaconda from its official website. We need to download the package from the official website of opencv.

The cv2.pyd file from this package needs to be copied to the directory of the Anaconda packages.

Then we need to set the environment variables for the compiler to detect opencv. We need to append %OPENCV_DIR%\bin to the User Variable PATH.

This method should be used as a last resort.

Conclusion

This tutorial discussed how to install opencv on Anaconda. We can use the pip command, the default package manager.

The conda command can also install opencv using the conda-forge channel. We discussed that we could run these commands on the Anaconda Prompt.

Another Anaconda application that can be used is the Anaconda Navigator, discussed in detail. Finally, we can also opt to download the package from the official website and install it manually.

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.

LinkedIn

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