Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否可以在docker?;中使用RPi.GPIO库;_Python_Docker_Raspberry Pi4 - Fatal编程技术网

Python 是否可以在docker?;中使用RPi.GPIO库;

Python 是否可以在docker?;中使用RPi.GPIO库;,python,docker,raspberry-pi4,Python,Docker,Raspberry Pi4,我使用了flask的官方docker图像。并在容器中安装了rpi.gpio库 pip install rpi.gpio 它成功了: root@e31ba5814e51:/app# pip install rpi.gpio Collecting rpi.gpio Downloading RPi.GPIO-0.7.0.tar.gz (30 kB) Building wheels for collected packages: rpi.gpio Building wheel for rpi.

我使用了flask的官方docker图像。并在容器中安装了rpi.gpio库

pip install rpi.gpio
它成功了:

root@e31ba5814e51:/app# pip install rpi.gpio
Collecting rpi.gpio
  Downloading RPi.GPIO-0.7.0.tar.gz (30 kB)
Building wheels for collected packages: rpi.gpio
  Building wheel for rpi.gpio (setup.py) ... done
  Created wheel for rpi.gpio: filename=RPi.GPIO-0.7.0-cp39-cp39-linux_armv7l.whl size=68495 sha256=0c2c43867c304f2ca21da6cc923b13e4ba22a60a77f7309be72d449c51c669db
  Stored in directory: /root/.cache/pip/wheels/09/be/52/39b324bfaf72ab9a47e81519994b2be5ddae1e99ddacd7a18e
Successfully built rpi.gpio
Installing collected packages: rpi.gpio
Successfully installed rpi.gpio-0.7.0
但它引发了以下错误:

Traceback (most recent call last):
  File "/app/hello/app2.py", line 2, in <module>
    import RPi.GPIO as GPIO
  File "/usr/local/lib/python3.9/site-packages/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
回溯(最近一次呼叫最后一次):
文件“/app/hello/app2.py”,第2行,在
将RPi.GPIO导入为GPIO
文件“/usr/local/lib/python3.9/site-packages/RPi/GPIO/_-init__.py”,第23行,在
从RPi.\u GPIO导入*
RuntimeError:此模块只能在Raspberry Pi上运行!
我在此链接中尝试了该方法,但无效:


我想知道是否可以这样做,如果可以,如何继续。

首先确保您将Docker容器作为“特权”运行,如下所示:

另外,再次检查您运行的映像是否要在处理器上运行


例如,如果您尝试在Raspberry Pi 4上运行“debian:latest”,它实际上会拉取“arm32v7/debian:latest”。

您确定您使用的基本映像用于armhf吗?
docker run --privileged -it debian:latest