open-cv installation in docker image does not work on raspberry pi

Question:

I have created python project with some dependencies, among them open-cv. Now I want to deploy my project in a docker image. For this, I created the following build-file on my local machine (running Ubuntu 22.04):

# syntax=docker/dockerfile:1

FROM python:3.8-slim-buster

WORKDIR /app

COPY requirements.txt .
COPY main.py .

RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6  -y

RUN pip3 install -r requirements.txt
CMD python3 main.py

Those are all of my requirements:

numpy==1.23.4
opencv-python==4.6.0.66
matplotlib==3.6.1
Pillow==9.3.0
XlsxWriter==3.0.3
keyboard==0.13.5

When building the image on my machine using

docker build --rm -t dockerfile:latest .

everything works fine. The image is built and I can use it how I intend to.

Now I wanted to build the image on a raspberry pi (running Raspbian GNU/Linux 11 (bullseye)). I have also tried this withFROM arm32v7/python:3.8-slim-buster, yielding the same results. The build fails with a very long error message:

    Installing build dependencies: started
  Installing build dependencies: finished with status 'error'
  error: subprocess-exited-with-error
  
  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [377 lines of output]
      Ignoring numpy: markers 'python_version == "3.6" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
      Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "linux" and platform_machine == "aarch64"' don't match your environment
      Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "darwin" and platform_machine == "arm64"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.9" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
      Ignoring numpy: markers 'python_version >= "3.10"' don't match your environment
      Collecting setuptools==59.2.0
        Using cached setuptools-59.2.0-py3-none-any.whl (952 kB)
      Collecting wheel==0.37.0
        Using cached wheel-0.37.0-py2.py3-none-any.whl (35 kB)
      Collecting cmake>=3.1
        Downloading cmake-3.25.0.tar.gz (33 kB)
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'done'
      Collecting pip
        Downloading pip-22.3.1-py3-none-any.whl (2.1 MB)
           ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 2.2 MB/s eta 0:00:00
      Collecting scikit-build>=0.13.2
        Using cached scikit_build-0.16.2-py3-none-any.whl (78 kB)
      Collecting numpy==1.17.3
        Downloading numpy-1.17.3.zip (6.4 MB)
           ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.4/6.4 MB 2.6 MB/s eta 0:00:00
        Preparing metadata (setup.py): started
        Preparing metadata (setup.py): finished with status 'done'
      Collecting distro
        Using cached distro-1.8.0-py3-none-any.whl (20 kB)
      Collecting packaging
        Using cached packaging-21.3-py3-none-any.whl (40 kB)
      Collecting pyparsing!=3.0.5,>=2.0.2
        Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
      Building wheels for collected packages: numpy, cmake
        Building wheel for numpy (setup.py): started
        Building wheel for numpy (setup.py): finished with status 'error'
        error: subprocess-exited-with-error
      
        × python setup.py bdist_wheel did not run successfully.
        │ exit code: 1
        ╰─> [263 lines of output]
            Running from numpy source directory.
            blas_opt_info:
            blas_mkl_info:
            customize UnixCCompiler
              libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            blis_info:
            customize UnixCCompiler
              libraries blis not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            openblas_info:
            customize UnixCCompiler
            customize UnixCCompiler
              libraries openblas not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            atlas_3_10_blas_threads_info:
            Setting PTATLAS=ATLAS
            customize UnixCCompiler
              libraries tatlas not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            atlas_3_10_blas_info:
            customize UnixCCompiler
              libraries satlas not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            atlas_blas_threads_info:
            Setting PTATLAS=ATLAS
            customize UnixCCompiler
              libraries ptf77blas,ptcblas,atlas not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            atlas_blas_info:
            customize UnixCCompiler
              libraries f77blas,cblas,atlas not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            accelerate_info:
              NOT AVAILABLE
      
            /tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/system_info.py:690: UserWarning:
                Optimized (vendor) Blas libraries are not found.
                Falls back to netlib Blas library which has worse performance.
                A better performance should be easily gained by switching
                Blas library.
              self.calc_info()
            blas_info:
            customize UnixCCompiler
              libraries blas not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            /tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/system_info.py:690: UserWarning:
                Blas (http://www.netlib.org/blas/) libraries not found.
                Directories to search for the libraries can be specified in the
                numpy/distutils/site.cfg file (section [blas]) or by setting
                the BLAS environment variable.
              self.calc_info()
            blas_src_info:
              NOT AVAILABLE
      
            /tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/system_info.py:690: UserWarning:
                Blas (http://www.netlib.org/blas/) sources not found.
                Directories to search for the sources can be specified in the
                numpy/distutils/site.cfg file (section [blas_src]) or by setting
                the BLAS_SRC environment variable.
              self.calc_info()
              NOT AVAILABLE
      
            /bin/sh: 1: svnversion: not found
            non-existing path in 'numpy/distutils': 'site.cfg'
            lapack_opt_info:
            lapack_mkl_info:
            customize UnixCCompiler
              libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            openblas_lapack_info:
            customize UnixCCompiler
            customize UnixCCompiler
              libraries openblas not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            openblas_clapack_info:
            customize UnixCCompiler
            customize UnixCCompiler
              libraries openblas,lapack not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            flame_info:
            customize UnixCCompiler
              libraries flame not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            atlas_3_10_threads_info:
            Setting PTATLAS=ATLAS
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries tatlas,tatlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/lib
            customize UnixCCompiler
              libraries tatlas,tatlas not found in /usr/lib
            <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
              NOT AVAILABLE
      
            atlas_3_10_info:
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries satlas,satlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/lib
            customize UnixCCompiler
              libraries satlas,satlas not found in /usr/lib
            <class 'numpy.distutils.system_info.atlas_3_10_info'>
              NOT AVAILABLE
      
            atlas_threads_info:
            Setting PTATLAS=ATLAS
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries ptf77blas,ptcblas,atlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/lib
            customize UnixCCompiler
              libraries ptf77blas,ptcblas,atlas not found in /usr/lib
            <class 'numpy.distutils.system_info.atlas_threads_info'>
              NOT AVAILABLE
      
            atlas_info:
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries f77blas,cblas,atlas not found in /usr/local/lib
            customize UnixCCompiler
              libraries lapack_atlas not found in /usr/lib
            customize UnixCCompiler
              libraries f77blas,cblas,atlas not found in /usr/lib
            <class 'numpy.distutils.system_info.atlas_info'>
              NOT AVAILABLE
      
            lapack_info:
            customize UnixCCompiler
              libraries lapack not found in ['/usr/local/lib', '/usr/lib']
              NOT AVAILABLE
      
            /tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/system_info.py:1712: UserWarning:
                Lapack (http://www.netlib.org/lapack/) libraries not found.
                Directories to search for the libraries can be specified in the
                numpy/distutils/site.cfg file (section [lapack]) or by setting
                the LAPACK environment variable.
              if getattr(self, '_calc_info_{}'.format(lapack))():
            lapack_src_info:
              NOT AVAILABLE
      
            /tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/system_info.py:1712: UserWarning:
                Lapack (http://www.netlib.org/lapack/) sources not found.
                Directories to search for the sources can be specified in the
                numpy/distutils/site.cfg file (section [lapack_src]) or by setting
                the LAPACK_SRC environment variable.
              if getattr(self, '_calc_info_{}'.format(lapack))():
              NOT AVAILABLE
      
            /usr/local/lib/python3.8/distutils/dist.py:274: UserWarning: Unknown distribution option: 'define_macros'
              warnings.warn(msg)
            running bdist_wheel
            running build
            running config_cc
            unifing config_cc, config, build_clib, build_ext, build commands --compiler options
            running config_fc
            unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
            running build_src
            build_src
            building py_modules sources
            creating build
            creating build/src.linux-armv7l-3.8
            creating build/src.linux-armv7l-3.8/numpy
            creating build/src.linux-armv7l-3.8/numpy/distutils
            building library "npymath" sources
            get_default_fcompiler: matching types: '['gnu95', 'intel', 'lahey', 'pg', 'absoft', 'nag', 'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor']'
            customize Gnu95FCompiler
            Could not locate executable gfortran
            Could not locate executable f95
            customize IntelFCompiler
            Could not locate executable ifort
            Could not locate executable ifc
            customize LaheyFCompiler
            Could not locate executable lf95
            customize PGroupFCompiler
            Could not locate executable pgfortran
            customize AbsoftFCompiler
            Could not locate executable f90
            Could not locate executable f77
            customize NAGFCompiler
            customize VastFCompiler
            customize CompaqFCompiler
            Could not locate executable fort
            customize IntelItaniumFCompiler
            Could not locate executable efort
            Could not locate executable efc
            customize IntelEM64TFCompiler
            customize GnuFCompiler
            Could not locate executable g77
            customize G95FCompiler
            Could not locate executable g95
            customize PathScaleFCompiler
            Could not locate executable pathf95
            customize NAGFORCompiler
            Could not locate executable nagfor
            don't know how to compile Fortran code on platform 'posix'
            C compiler: gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
      
            compile options: '-Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/usr/local/include/python3.8 -c'
            gcc: _configtest.c
            failure.
            removing: _configtest.c _configtest.o
            Traceback (most recent call last):
              File "<string>", line 2, in <module>
              File "<pip-setuptools-caller>", line 34, in <module>
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/setup.py", line 443, in <module>
                setup_package()
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/setup.py", line 435, in setup_package
                setup(**metadata)
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/core.py", line 171, in setup
                return old_setup(**new_attr)
              File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
                return distutils.core.setup(**attrs)
              File "/usr/local/lib/python3.8/distutils/core.py", line 148, in setup
                dist.run_commands()
              File "/usr/local/lib/python3.8/distutils/dist.py", line 966, in run_commands
                self.run_command(cmd)
              File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
                cmd_obj.run()
              File "/usr/local/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 325, in run
                self.run_command("build")
              File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
                self.distribution.run_command(command)
              File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
                cmd_obj.run()
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/command/build.py", line 47, in run
                old_build.run(self)
              File "/usr/local/lib/python3.8/distutils/command/build.py", line 135, in run
                self.run_command(cmd_name)
              File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
                self.distribution.run_command(command)
              File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
                cmd_obj.run()
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/command/build_src.py", line 142, in run
                self.build_sources()
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/command/build_src.py", line 153, in build_sources
                self.build_library_sources(*libname_info)
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/command/build_src.py", line 286, in build_library_sources
                sources = self.generate_sources(sources, (lib_name, build_info))
              File "/tmp/pip-install-b1zdl1d3/numpy_c51059096ab144ca9ad2b38cd023e512/numpy/distutils/command/build_src.py", line 369, in generate_sources
                source = func(extension, build_dir)
              File "numpy/core/setup.py", line 669, in get_mathlib_info
                raise RuntimeError("Broken toolchain: cannot link a simple C program")
            RuntimeError: Broken toolchain: cannot link a simple C program
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for numpy
        Running setup.py clean for numpy
        error: subprocess-exited-with-error
      
        × python setup.py clean did not run successfully.
        │ exit code: 1
        ╰─> [10 lines of output]
            Running from numpy source directory.
      
            `setup.py clean` is not supported, use one of the following instead:
      
              - `git clean -xdf` (cleans all files)
              - `git clean -Xdf` (cleans all versioned files, doesn't touch
                                  files that aren't checked into the git repo)
      
            Add `--force` to your command to use it anyway if you must (unsupported).
      
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed cleaning build dir for numpy
        Building wheel for cmake (pyproject.toml): started
        Building wheel for cmake (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error
      
        × Building wheel for cmake (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [33 lines of output]
            Traceback (most recent call last):
              File "/tmp/pip-build-env-q0a3b44q/overlay/lib/python3.8/site-packages/skbuild/setuptools_wrap.py", line 612, in setup
                cmkr = cmaker.CMaker(cmake_executable)
              File "/tmp/pip-build-env-q0a3b44q/overlay/lib/python3.8/site-packages/skbuild/cmaker.py", line 148, in __init__
                self.cmake_version = get_cmake_version(self.cmake_executable)
              File "/tmp/pip-build-env-q0a3b44q/overlay/lib/python3.8/site-packages/skbuild/cmaker.py", line 103, in get_cmake_version
                raise SKBuildError(
      
      
                =============================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.8.15
                platform: Linux-5.15.32-v7l+-armv7l-with-glibc2.4
                glibc: glibc 2.28
                machine: armv7l
                bits: 32
                pip: n/a
                setuptools: 65.6.3
                scikit-build: 0.16.2
                PEP517_BUILD_BACKEND=setuptools.build_meta
                =============================DEBUG ASSISTANCE=============================
      
            Problem with the CMake installation, aborting build. CMake executable is cmake
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for cmake
      Failed to build numpy cmake
      ERROR: Could not build wheels for cmake, which is required to install pyproject.toml-based projects
      WARNING: You are using pip version 22.0.4; however, version 22.3.1 is available.
      You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
WARNING: You are using pip version 22.0.4; however, version 22.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

I have tried to base my image on other images:

  • FROM ubuntu:22:04 (additionally installing python and pip)
  • FROM python:3.9
  • FROM python:3.8-bullseye

I have also tried other python versions. Those do not give an error, but when it comes to installing open-cv, it says

Installing build dependencies: started
Installing build dependencies: still running...

while repeating the latter (endlessly it seems, I let it run for about 15min without any changes).

I have also tried adding the following (after researching stackoverflow):

RUN apt-get install lbhdf5-dev libhdf5-serial-dev libatlas-base-dev -y

without any results.

I also tried building the image on my local machine nad loading it on the raspberry, yielding the following error message when running the container:

The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7) and no specific platform was requested
exec /bin/sh: exec format error

Thanks in advance for any help.

Asked By: wittn

||

Answers:

I solved this by updating the Raspberry Pi to a 64-Bit installation.

Answered By: wittn
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.