Raspbian/Stretch docker GPIO RuntimeError: (This module can only be run on a Raspberry Pi!)

1.5k Views Asked by At

Hello Stack overflow community, I am working on running a docker image with GPIO and run into a GPIO runtime error: This module can only be run on a Raspberry Pi!

When I was running the code, this is what I got:

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!

The environment I used is Raspberry pi4 with the following system info and language info:

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

For the docker image, I have the following system environment:

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 <[email protected]>
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

To run the docker image, I have used the following to start the container:

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

Since both the docker and system are using raspberry pi and Raspbian system, I cannot diagnose where is the problem. Is there anything else I suppose to check? What else can be the problem here?

Thanks!

0

There are 0 best solutions below