pythonopencvgoogle-colaboratory

Install of opencv-python-headless takes a long time


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


Solution

  • 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"