Setup OpenCV for python in any platform.

Yashod Perera
Nov 3, 2020
Photo by Hitesh Choudhary on Unsplash

Setting OpenCV for python is piece of cake. Are you fed up with lots of tutorials. Let’s do it within 5 minutes.

First what we need is a virtual environment. venv is using for this tutorial and you can use any other tutorial as you preferred.

First let’s set up an virtual environment.

python3 -m venv virtual_environment

Then activate the virtual environment as follows.

source virtual_environment/bin/activate
Once the virtual environment is activated its’ name should be shown in brackets as in the third line.

Then install the OpenCV using one command. What using one command. Yes!

pip install opencv-python

Done!.

You can use OpenCV inside the virtual environment and you can install any other python packages also.

Bonus Chapter

Let’s check whether the OpenCV is set up correctly. Make sure that you have activated the virtual environment and let’s make a simple python file naming test.py as follows to print the version of the OpenCV.

import cv2print("OpenCv version " + cv2.__version__)

Then run the file inside the virtual environment.

python3 test.py

Then it should show as follows.

You are ready to go.

Following link is for setting up virtual environment using pipenv.

Hopefully this is helpful.

If you have found this helpful please hit that 👏 and share it on social media :).

--

--

Yashod Perera

Technical Writer | Tech Enthusiast | Open source contributor