简体   繁体   English

在 Python 中未找到 RPi.GPIO

[英]RPi.GPIO Not Found in Python 3

I am trying to get the GPIO module working on a Raspberry Pi 3B+.我正在尝试让 GPIO 模块在 Raspberry Pi 3B+ 上工作。 I have installed the libraries as below.我已经安装了如下库。 It works fine in Python2 but not Python 3 (version 3.9).它在 Python2 中运行良好,但在 Python 3(3.9 版)中运行良好。 Any ideas would be appreciated.任何想法,将不胜感激。

pi@raspberrypi:/usr/bin $ sudo apt-get install python-rpi.gpio python3-rpi.gpio
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-rpi.gpio is already the newest version (0.6.5~stretch-1).
python3-rpi.gpio is already the newest version (0.6.5~stretch-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
pi@raspberrypi:/usr/bin $ python2
Python 2.7.13 (default, Aug 22 2020, 10:03:02) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
>>> 
pi@raspberrypi:/usr/bin $ python3
Python 3.9.0 (default, Jan 27 2021, 16:17:29) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'RPi'
>>> 

You should run the following command in the terminal to install the RPi module which contains GPIO : pip3 install rpi-gpio您应该在终端中运行以下命令来安装包含GPIORPi模块: pip3 install rpi-gpio

These commands will download and install the RPi module.这些命令将下载并安装RPi模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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