(Docker) "Failed building wheel for cmake" error when trying to install opencv-python

Question:

Here’s a Dockerfile that demonstrates the problem:

FROM php:7.1

RUN apt-get update
RUN apt-get install -y python3-pip
RUN pip3 install opencv-python

It works fine if I do FROM php:8.0 but not FROM php:7.1. The error I get is as follows:

    Running setup.py bdist_wheel for cmake: finished with status 'error'
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-f4o4i380/cmake/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-hc4d6dtu --python-tag cp37:
    Traceback (most recent call last):
      File "/tmp/pip-build-env-qno2yg1l/lib/python3.7/site-packages/skbuild/setuptools_wrap.py", line 613, in setup
        cmkr = cmaker.CMaker(cmake_executable)
      File "/tmp/pip-build-env-qno2yg1l/lib/python3.7/site-packages/skbuild/cmaker.py", line 141, in __init__
        self.cmake_version = get_cmake_version(self.cmake_executable)
      File "/tmp/pip-build-env-qno2yg1l/lib/python3.7/site-packages/skbuild/cmaker.py", line 96, in get_cmake_version
        "Problem with the CMake installation, aborting build. CMake executable is %s" % cmake_executable


        =============================DEBUG ASSISTANCE=============================
        If you are seeing a compilation error please try the following steps to
        successfully install cmake:
        1) Upgrade to the latest pip and try again. This will fix errors for most
           users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
        2) If on Linux, with glibc < 2.12, you can set PIP_ONLY_BINARY=cmake in
           order to retrieve the last manylinux1 compatible wheel.
        3) If on Linux, with glibc < 2.12, you can cap "cmake<3.23" in your
           requirements in order to retrieve the last manylinux1 compatible wheel.
        4) Open an issue with the debug information that follows at
           https://github.com/scikit-build/cmake-python-distributions/issues

        Python: 3.7.3
        platform: Linux-4.19.128-microsoft-standard-x86_64-with-debian-10.2
        glibc: glibc 2.28
        machine: x86_64
        bits: 64
        pip: 18.1
        setuptools: 65.3.0
        scikit-build: 0.15.0
        =============================DEBUG ASSISTANCE=============================

    Problem with the CMake installation, aborting build. CMake executable is cmake

    ----------------------------------------
    Failed building wheel for cmake
    Running setup.py clean for cmake
  Failed to build cmake
Asked By: neubert

||

Answers:

I got this working. I needed to add RUN pip3 install --upgrade pip setuptools wheel to my Dockerfile after RUN apt-get install -y python3-pip.

Answered By: neubert
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.