简体   繁体   中英

Installing opencv2 in Docker for Raspberry Pi (new OS image Bullseye)

I'm trying to install an opencv2 for Docker container in my Raspberry Pi with the newest OS image.

Here is my Dockerfile

# syntax=docker/dockerfile:1

FROM python:latest

WORKDIR /app

COPY req.txt req.txt

RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6  -y
RUN pip3 install -r req.txt

COPY . .

CMD ["python3", "main.py"]



requirements contains

opencv-python-headless==4.5.4.58

And I'm getting this error:

Setting up libxvidcore4:armhf (2:1.3.7-1) ...
Setting up libx264-160:armhf (2:0.160.3011+gitcde9a93-2.1) ...
Setting up libxxf86vm1:armhf (1:1.1.4-1+b2) ...
Setting up libsnappy1v5:armhf (1.1.8-1) ...
Setting up libflac8:armhf (1.3.3-2) ...
Setting up libxcb-present0:armhf (1.14-3) ...
Setting up libasound2-data (1.2.4-1.1) ...
Setting up libz3-4:armhf (4.8.10-1) ...
Setting up libblas3:armhf (3.9.0-3) ...
update-alternatives: using /usr/lib/arm-linux-gnueabihf/blas/libblas.so.3 to provide /usr/lib/arm-linux-gnueabihf/libblas.so.3 (libblas.so.3-arm-linux-gnueabihf) in auto mode
Setting up libllvm11:armhf (1:11.0.1-2) ...
Setting up libass9:armhf (1:0.15.0-2) ...
Setting up libslang2:armhf (2.3.2-5) ...
Setting up libva2:armhf (2.10.0-1) ...
Setting up libwrap0:armhf (7.6.q-31) ...
Setting up libxfixes3:armhf (1:5.0.3-2) ...
Setting up libxcb-sync1:armhf (1.14-3) ...
Setting up libcodec2-0.9:armhf (0.9.2-4) ...
Setting up libdbus-1-3:armhf (1.12.20-2) ...
Setting up dbus (1.12.20-2) ...
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Setting up libopus0:armhf (1.3.1-0.1) ...
Setting up libxinerama1:armhf (2:1.1.4-2) ...
Setting up libxv1:armhf (2:1.0.11-1) ...
Setting up libvorbis0a:armhf (1.3.7-1) ...
Setting up libxrandr2:armhf (2:1.5.1-1) ...
Setting up libsensors5:armhf (1:3.6.0-7) ...
Setting up libaacs0:armhf (0.9.0-2) ...
Setting up pocketsphinx-en-us (0.8+5prealpha+1-13) ...
Setting up libglapi-mesa:armhf (20.3.5-1) ...
Setting up libgfortran5:armhf (10.2.1-6) ...
Setting up libvulkan1:armhf (1.2.162.0-1) ...
Setting up libxcb-dri2-0:armhf (1.14-3) ...
Setting up libbdplus0:armhf (0.1.2-3) ...
Setting up libvidstab1.1:armhf (1.1.0-2+b1) ...
Setting up alsa-topology-conf (1.2.4-1) ...
Setting up ocl-icd-libopencl1:armhf (2.2.14-2) ...
Setting up libasyncns0:armhf (0.8-6+b2) ...
Setting up libxshmfence1:armhf (1.3-1) ...
Setting up libvpx6:armhf (1.9.0-1) ...
Setting up libvdpau1:armhf (1.4-3) ...
Setting up libwavpack1:armhf (5.4.0-1) ...
Setting up libbs2b0:armhf (3.1.0+dfsg-2.2+b1) ...
Setting up libxcb-randr0:armhf (1.14-3) ...
Setting up libtheora0:armhf (1.1.1+dfsg.1-15) ...
Setting up libasound2:armhf (1.2.4-1.1) ...
Setting up libopenal-data (1:1.19.1-2) ...
Setting up libwayland-egl1:armhf (1.18.0-2~exp1.1) ...
Setting up libusb-1.0-0:armhf (2:1.0.24-3) ...
Setting up libbluray2:armhf (1:1.2.1-4+deb11u1) ...
Setting up libsamplerate0:armhf (0.2.1+ds0-1) ...
Setting up libdrm-common (2.4.104-1) ...
Setting up libzvbi-common (0.2.35-18) ...
Setting up libmp3lame0:armhf (3.100-3) ...
Setting up libvorbisenc2:armhf (1.3.7-1) ...
Setting up libiec61883-0:armhf (1.2.0-4) ...
Setting up libserd-0-0:armhf (0.30.10-2) ...
Setting up libxkbcommon0:armhf (1.0.3-2) ...
Setting up libwayland-client0:armhf (1.18.0-2~exp1.1) ...
Setting up libavc1394-0:armhf (0.5.4-5) ...
Setting up libzvbi0:armhf (0.2.35-18) ...
Setting up liblapack3:armhf (3.9.0-3) ...
update-alternatives: using /usr/lib/arm-linux-gnueabihf/lapack/liblapack.so.3 to provide /usr/lib/arm-linux-gnueabihf/liblapack.so.3 (liblapack.so.3-arm-linux-gnueabihf) in auto mode
Setting up libzmq5:armhf (4.3.4-1) ...
Setting up libcaca0:armhf (0.99.beta19-2.2) ...
Setting up alsa-ucm-conf (1.2.4-2) ...
Setting up libcdio-cdda2:armhf (10.2+2.0.0-1+b2) ...
Setting up libcdio-paranoia2:armhf (10.2+2.0.0-1+b2) ...
Setting up libxcursor1:armhf (1:1.2.0-2) ...
Setting up libvorbisfile3:armhf (1.3.7-1) ...
Setting up libdc1394-25:armhf (2.2.6-3) ...
Setting up librubberband2:armhf (1.9.0-1) ...
Setting up libsndio7.0:armhf (1.5.0-3) ...
Setting up libjack-jackd2-0:armhf (1.9.17~dfsg-1) ...
Setting up libdrm2:armhf (2.4.104-1) ...
Setting up libflite1:armhf (2.2-2) ...
Setting up libva-drm2:armhf (2.10.0-1) ...
Setting up libsord-0-0:armhf (0.16.8-2) ...
Setting up libwayland-cursor0:armhf (1.18.0-2~exp1.1) ...
Setting up libsratom-0-0:armhf (0.6.8-1) ...
Setting up libsndfile1:armhf (1.0.31-2) ...
Setting up libva-x11-2:armhf (2.10.0-1) ...
Setting up liblilv-0-0:armhf (0.24.12-2) ...
Setting up libopenmpt0:armhf (0.4.11-1) ...
Setting up libdrm-amdgpu1:armhf (2.4.104-1) ...
Setting up mesa-vulkan-drivers:armhf (20.3.5-1) ...
Setting up libdrm-nouveau2:armhf (2.4.104-1) ...
Setting up libgbm1:armhf (20.3.5-1) ...
Setting up libpulse0:armhf (14.2-2) ...
Setting up libdrm-radeon1:armhf (2.4.104-1) ...
Setting up libgl1-mesa-dri:armhf (20.3.5-1) ...
Setting up libopenal1:armhf (1:1.19.1-2) ...
Setting up libavutil56:armhf (7:4.3.3-0+deb11u1) ...
Setting up libpostproc55:armhf (7:4.3.3-0+deb11u1) ...
Setting up libswscale5:armhf (7:4.3.3-0+deb11u1) ...
Setting up mesa-va-drivers:armhf (20.3.5-1) ...
Setting up libsdl2-2.0-0:armhf (2.0.14+dfsg2-3) ...
Setting up mesa-vdpau-drivers:armhf (20.3.5-1) ...
Setting up libglx-mesa0:armhf (20.3.5-1) ...
Setting up libglx0:armhf (1.3.2-1) ...
Setting up libsphinxbase3:armhf (0.8+5prealpha+1-12) ...
Setting up libswresample3:armhf (7:4.3.3-0+deb11u1) ...
Setting up libavresample4:armhf (7:4.3.3-0+deb11u1) ...
Setting up libpocketsphinx3:armhf (0.8+5prealpha+1-13) ...
Setting up libgl1:armhf (1.3.2-1) ...
Setting up va-driver-all:armhf (2.10.0-1) ...
Setting up libavcodec58:armhf (7:4.3.3-0+deb11u1) ...
Setting up libvdpau-va-gl1:armhf (0.4.2-1+b1) ...
Setting up libchromaprint1:armhf (1.5.0-2) ...
Setting up libavformat58:armhf (7:4.3.3-0+deb11u1) ...
Setting up vdpau-driver-all:armhf (1.4-3) ...
Setting up libavfilter7:armhf (7:4.3.3-0+deb11u1) ...
Setting up libavdevice58:armhf (7:4.3.3-0+deb11u1) ...
Setting up ffmpeg (7:4.3.3-0+deb11u1) ...
Processing triggers for libc-bin (2.31-13+deb11u2) ...
Removing intermediate container 1ba73a14a49a
 ---> 0542e1937cad
Step 6/8 : RUN pip3 install -r req.txt
 ---> Running in c2bc64e20849
Collecting certifi==2021.10.8
  Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
Collecting charset-normalizer==2.0.7
  Downloading charset_normalizer-2.0.7-py3-none-any.whl (38 kB)
Collecting click==8.0.3
  Downloading click-8.0.3-py3-none-any.whl (97 kB)
Collecting Flask==2.0.2
  Downloading Flask-2.0.2-py3-none-any.whl (95 kB)
Collecting idna==3.3
  Downloading idna-3.3-py3-none-any.whl (61 kB)
Collecting influxdb-client==1.23.0
  Downloading influxdb_client-1.23.0-py3-none-any.whl (522 kB)
Collecting itsdangerous==2.0.1
  Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting Jinja2==3.0.2
  Downloading Jinja2-3.0.2-py3-none-any.whl (133 kB)
Collecting MarkupSafe==2.0.1
  Downloading MarkupSafe-2.0.1.tar.gz (18 kB)
Collecting numpy==1.21.4
  Downloading numpy-1.21.4.zip (10.6 MB)
  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 wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Collecting opencv-python-headless==4.5.4.58
  Downloading opencv-python-headless-4.5.4.58.tar.gz (89.8 MB)
  Installing build dependencies: started
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: still running...
  Installing build dependencies: finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python /tmp/pip-standalone-pip-et3mksl1/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-li1hlg53/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.17.3; python_version=='"'"'3.8'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.19.3; python_version<='"'"'3.9'"'"' and sys_platform == '"'"'linux'"'"' and platform_machine == '"'"'aarch64'"'"'' 'numpy==1.21.0; python_version<='"'"'3.9'"'"' and sys_platform == '"'"'darwin'"'"' and platform_machine == '"'"'arm64'"'"'' 'numpy==1.19.3; python_version=='"'"'3.9'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.21.2; python_version>='"'"'3.10'"'"''
       cwd: None
  Complete output (71 lines):
  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.8" 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
  Collecting setuptools
    Downloading setuptools-58.5.3-py3-none-any.whl (946 kB)
  Collecting wheel
    Downloading wheel-0.37.0-py2.py3-none-any.whl (35 kB)
  Collecting scikit-build
    Downloading scikit_build-0.12.0-py2.py3-none-any.whl (73 kB)
  Collecting cmake
    Downloading cmake-3.21.4.tar.gz (31 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 wheel metadata: started
      Preparing wheel metadata: finished with status 'done'
  Collecting pip
    Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
  Collecting numpy==1.21.2
    Downloading numpy-1.21.2.zip (10.3 MB)
    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 wheel metadata: started
      Preparing wheel metadata: finished with status 'done'
  Collecting packaging
    Using cached packaging-21.2-py3-none-any.whl (40 kB)
  Collecting distro
    Using cached distro-1.6.0-py2.py3-none-any.whl (19 kB)
  Collecting pyparsing<3,>=2.0.2
    Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
  Building wheels for collected packages: numpy, cmake
    Building wheel for numpy (PEP 517): started
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): still running...
    Building wheel for numpy (PEP 517): finished with status 'done'
    Created wheel for numpy: filename=numpy-1.21.2-cp310-cp310-linux_armv7l.whl size=16741198 sha256=5b4a1047de379ce3106c19b339167afcf9845366cd1f027d737b8c45f962940d
    Stored in directory: /root/.cache/pip/wheels/55/ca/9f/48d8bbedba076d0949e6d329c6aad3705267c63cc38521852d
    Building wheel for cmake (PEP 517): started
    Building wheel for cmake (PEP 517): finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python /tmp/tmpwvmh9dg5_in_process.py build_wheel /tmp/tmpll8wsnma
         cwd: /tmp/pip-install-fbue14m3/cmake_b604147fe6164d639ebb2ae896d8d802
    Complete output (9 lines):
      File "/tmp/pip-build-env-r9cuk4k1/overlay/lib/python3.10/site-packages/skbuild/setuptools_wrap.py", line 564, in setup
        cmkr = cmaker.CMaker(cmake_executable)
      File "/tmp/pip-build-env-r9cuk4k1/overlay/lib/python3.10/site-packages/skbuild/cmaker.py", line 95, in __init__
        self.cmake_version = get_cmake_version(self.cmake_executable)
      File "/tmp/pip-build-env-r9cuk4k1/overlay/lib/python3.10/site-packages/skbuild/cmaker.py", line 81, in get_cmake_version
        raise SKBuildError(
    Traceback (most recent call last):
  
    Problem with the CMake installation, aborting build. CMake executable is cmake
    ----------------------------------------
    ERROR: Failed building wheel for cmake
  Successfully built numpy
  Failed to build cmake
  ERROR: Could not build wheels for cmake which use PEP 517 and cannot be installed directly
  WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
  You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/b3/6c/4cdac3b2eb23337321a5e7d2db55ed0a1348333db99085f96e93c7cf18d0/opencv-python-headless-4.5.4.58.tar.gz#sha256=3e32018e65eabc9aab10c7a109be5f735cf2c3934a47025b6903dcec034d460b (from https://pypi.org/simple/opencv-python-headless/) (requires-python:>=3.6). Command errored out with exit status 1: /usr/local/bin/python /tmp/pip-standalone-pip-et3mksl1/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-li1hlg53/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.17.3; python_version=='"'"'3.8'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.19.3; python_version<='"'"'3.9'"'"' and sys_platform == '"'"'linux'"'"' and platform_machine == '"'"'aarch64'"'"'' 'numpy==1.21.0; python_version<='"'"'3.9'"'"' and sys_platform == '"'"'darwin'"'"' and platform_machine == '"'"'arm64'"'"'' 'numpy==1.19.3; python_version=='"'"'3.9'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.21.2; python_version>='"'"'3.10'"'"'' Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement opencv-python-headless==4.5.4.58 (from versions: 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.15.55, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.3.56, 4.5.4.58)
ERROR: No matching distribution found for opencv-python-headless==4.5.4.58
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
The command '/bin/sh -c pip3 install -r req.txt' returned a non-zero code: 1
Unable to find image 'influxdb:latest' locally
latest: Pulling from library/influxdb
docker: no matching manifest for linux/arm/v7 in the manifest list entries.
See 'docker run --help'.
Unable to find image 'ultimate_hydroponics:latest' locally
docker: Error response from daemon: pull access denied for ultimate_hydroponics, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

EDIT error doesn't changes even if I change opencv2 version or python version I also tried FROM arm32v7/python:latest no change

If you haven't solved this already, your error is nothing to do with opencv - it's cmake:

Building wheel for cmake (PEP 517): finished with status 'error'

which is required to install opencv.

You may find this thread helpful: ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly - there's an answer in that list that contains a Dockerfile which may work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM