RPi.GPIOを使いたい。
環境
2020-12-02-raspios-buster-armhf-lite.zip
pi@raspberrypi:~ $ cat /etc/issue
Raspbian GNU/Linux 10 \n \l
Python2 なら使えるが
$ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
Python3 だと使えないので
pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'RPi'
まず PIP3 をレポジトリからインストール
$ sudo apt install python3-pip
.
.
.
0 upgraded, 25 newly installed, 0 to remove and 33 not upgraded.
Need to get 51.4 MB of archives.
After this operation, 84.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
.
.
.
次に rpi.gpio を入れる
$ sudo pip3 install rpi.gpio
$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
使えました