1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RaspberryPi OS に Python3 用の RPi.GPIO を入れる

Last updated at Posted at 2021-02-15

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

使えました

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?