How to Install OpenCV using pip

How to Install OpenCV using pip : 3 Methods

GET FREE AMZAON AUDIOBOOKS

I have seen many python programmers have faced difficulties while installing OpenCV. They are getting some error like no module named cv2 when they import or use OpenCV code. Therefore I have come here with a “how-to ” tutorial on “How to Install OpenCV using pip“.  In this entire post, you will know the various methods to install OpenCV using pip.

Method 1: Installing pre-built OpenCV package using pip

In this method, I will show you how you can install OpenCV directly use the pip command. There is an unofficial pre-built OpenCV package for Python that allows you to do so.

Open your command prompt and type the following command. You should also remember that the pip command differs for different python versions. Therefore make sure you check the python version using the following command.

python --version

In my case, it is 3.7.4. However, I am showing you how to install on both python versions, python 2.xx, and python 3.xx. That’s why use according to it.

For python 2.xx version

pip install opencv-python

For python 3.xx version

pip3 install opencv-python
Installing Pre-built OpenCV python module using pip
Installing Pre-built OpenCV python module using pip

 

You can see I have already installed OpenCV on my computer. Otherwise, it will start downloading the package and install OpenCV.

Method 2: Install Opencv using pip on the whl file

The other method to install OpenCV in your system is using the .whl file. The whl file is a package saved in the wheel format that is used for package distribution in python. But before installing using this method make sure you have already installed numpy. Go to the repository website and search for the OpenCV package. There you will different versions of the OpenCV packages. Download the wheel file according to your system. My OS is windows, so I am downloading the win32 version.

OpenCV Version
OpenCV Version repository

After downloading it, go to that directory using the command prompt and type the pip3 command to install OpenCV.

pip3 install opencv_python-4.4.0-cp39-cp39-win32.whl

It will compile the wheel file and install the OpenCV package in your system.

Method 3: Installing OpenCV using pip in Pycharm

Sometimes we are unable to install the OpenCV package inside the Pycharm directly. Then the pip command will help you. Just go to the terminal inside the PyCharm and type the following command. It will install the OpenCV python package.

pip3 install opencv-python

Installing OpenCV using pip inside the Pycharm
Installing OpenCV using pip inside the Pycharm

Conclusion

OpenCV is a library for making the computer vision task very easy. It allows you to manipulate images and videos efficiently. But many beginners are unable to install it in their system. These are the methods I have aggregated for you that will be very helpful for you in installing OpenCV. Even if you are unable to install it then you can contact us for more help.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner