Install of opencv-python-headless takes a long time

Viewed 15315

When I install opencv-python-headless in Google Colab, it takes 15 minutes to complete.

My code:

! pip install --upgrade pip
! pip install opencv-python-headless

Here's a notebook with this code which recreates the problem: https://colab.research.google.com/gist/mherzog01/38b6cf71942a443da072f09bc097387f/slow-install-of-opencv-python-headless.ipynb.

The process eventually completes, but I'd like to reduce the time to install.

I saw from `Building wheel for opencv-python (PEP 517) ... -` runs forever a discussion about compiling OpenCV, which could very well be what is happening here. However, this same SO post states that if you upgrade pip, it will use pre-built wheels.

Edit: Added @intsco's workaround to the Google Colab

2 Answers

Might be related to changes in OpenCV >=4.3 wheels https://github.com/skvark/opencv-python#backward-compatibility

Starting from 4.3.0 and 3.4.10 builds the Linux build environment was updated from manylinux1 to manylinux2014. This dropped support for old Linux distributions.

My workaround: pip install "opencv-python-headless<4.3"

The install takes a long time since pip built the package from sources. The reason for that was that a new opencv-python-headless release was published to PyPI probably around the same time you tried to install it. It takes several hours for all the pre-built wheels to appear to PyPI. I believe the install works now fast, since all the wheels are in PyPI: https://pypi.org/project/opencv-python-headless/4.4.0.46/#files

This problem can be avoided by pinning the version, e.g. pip install opencv-python-headless==4.4.0.44, and upgrading manually when needed.

Related