首页 > 解决方案 > 为 Raspberry Pi 构建 Python IoTEdge 模块

问题描述

我正在尝试为 Raspberry Pi 4 构建 Python IoTEdge 模块(使用 Docker 构建映像)。

我将 IoTEdge 解决方案的目标架构设置为arm32v7

我不相信我的 有什么问题requirements.txt,但仅供参考:

要求.txt

azure-iot-device~=2.0.0
opencv-python
numpy
requests

Dockerfile

FROM arm32v7/python:3.7-slim-buster

WORKDIR /app

COPY requirements.txt ./
RUN pip install -r requirements.txt

COPY . .

CMD [ "python3", "-u", "./main.py" ]

我运行以下命令:

docker build  --rm -f "path/to/Dockerfile" -t dockerTag "path/to/module/project"

但是,我收到以下错误:

Step 4/7 : RUN pip install -r requirements.txt
 ---> Running in 515aac4bdc38
standard_init_linux.go:219: exec user process caused: exec format error

我在这里读到要构建到 ARM,我必须使用它docker buildx。我buildx--platform linux/arm32. 我切换到使用这个容器,然后运行:

docker buildx build --platform linux/arm32 --rm -f "path/to/Dockerfile" -t dockerTag "path/to/module/project"

但是,现在我得到:

 => ERROR [4/7] RUN pip install -r requirements.txt                                                                                                                        2.2s
------                                                                                                                                                                          
 > [4/5] RUN pip install -r requirements.txt:
#8 0.727 standard_init_linux.go:219: exec user process caused: exec format error
------
Dockerfile.arm32v7:22
--------------------
  20 |     #     libcurl4-openssl-dev
  21 |     
  22 | >>> RUN pip install -r requirements.txt
  23 |     
  24 |     COPY . .
--------------------
error: failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

我的开发机器:

我也尝试直接在 Raspberry Pi 4 本身上构建它,但是,它给了我同样的错误。我不知道该怎么办。有什么建议么?

标签: pythondockerraspberry-piazure-iot-edgeazure-container-registry

解决方案


奇怪的是,当我在 Windows 机器上而不是使用 Manjaro Linux 时,它成功构建了。我还是想知道为什么...


推荐阅读