0

你好 Stack 溢出社区,我正在使用 GPIO 运行 docker 映像并遇到 GPIO 运行时错误:此模块只能在 Raspberry Pi 上运行!

当我运行代码时,这就是我得到的:

Traceback (most recent call last):
  File "Voice_control.py", line 7, in <module>
    from picar.back_wheels import Back_Wheels
  File "/home/app/picar/__init__.py", line 3, in <module>
    from .import back_wheels
  File "/home/app/picar/back_wheels.py", line 15, in <module>
    from .SunFounder_TB6612 import TB6612
  File "/home/app/picar/SunFounder_TB6612/TB6612.py", line 13, in <module>
    import RPi.GPIO as GPIO
  File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!

我使用的环境是 Raspberry pi4,具有以下系统信息和语言信息:

Linux basementpi 5.10.17-v7l+ #1421 SMP Thu May 27 14:00:13 BST 2021 armv7l GNU/Linux
Docker version 20.10.7, build f0df350
Python 3.7.3

对于 docker 镜像,我有以下系统环境:

Linux 0e3ae4f729e1 5.10.17-v7l+ #1421 SMP Thu May 27 14:00:13 BST 2021 armv7l GNU/Linux
Python 3.5.3

Package: python3-rpi.gpio
Version: 0.6.5~stretch-1
Priority: optional
Section: python
Source: rpi.gpio
Maintainer: Ben Croston <ben@croston.org>
Installed-Size: 75.8 kB
Depends: libc6 (>= 2.7), python3 (<< 3.6), python3 (>= 3.5~), python3:any (>= 3.3.2-2~)
Homepage: http://sourceforge.net/projects/raspberry-gpio-python/
Download-Size: 23.6 kB
APT-Manual-Installed: yes
APT-Sources: http://archive.raspberrypi.org/debian stretch/main armhf Packages
Description: Python 3 GPIO module for Raspberry Pi
 This is the RPi.GPIO Python 3 module, for supporting GPIO on a
 Raspberry Pi

为了运行 docker 镜像,我使用了以下命令来启动容器:

$ docker run --privileged -d <image name>

由于 docker 和系统都使用树莓派和 Raspbian 系统,我无法诊断问题出在哪里。还有什么我想检查的吗?这里还有什么问题?

谢谢!

4

0 回答 0