logo

How to install the cv2 and PIL packages with pip in Python 📂Programing

How to install the cv2 and PIL packages with pip in Python

Guide

The openCV and PIL packages are useful for image processing. The problem is that when importing these packages in example codes, they are usually referred to as cv2 and PIL, but attempting to install them with pip in Python throws an error. This is due to the difference between the names used for importing and those used for installing.

openCV

20191029_094725.png

As seen in the screenshot, to install openCV, one must not use cv2 or openCV but rather install openCV-python as follows.

pip3 install openCV-python

PIL

20191029_094926.png

The case with PIL is even more bizarre, as one must install pillow instead. PIL stands for Python Image Library, but what “low” stands for or means is elusive. It can be installed with the following command.

pip3 install pillow