raspberryPiOSLite(64bit)を書き込んで、venvを使って、RPI.GPIOをインストールしようとしたらエラーが出たんだよなぁ〜〜

経緯

家のwifiルータを変えたので、その変更をラズパイゼロ2にも反映させよう〜と思ったけどうまく設定することができなかったのでいっそのこと新しくosを書きこむことにした。

その際に(せっかくなので!)raspberry Pi OS Lite(64bit)を入れることにした。

エラーが出てきた!!!

その後、なんやかんやして、venvを作ってsource env/bin/activate みたいな感じをして。 pip install rpi.gpioをしたところこんな感じのエラーが出てきた

(env) ユーザー名等々@ユーザー名等々:~/src/servo_test $ pip install RPi.GPIO
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting RPi.GPIO
Using cached RPi.GPIO-0.7.1.tar.gz (29 kB)
Using legacy 'setup.py install' for RPi.GPIO, since package 'wheel' is not installed.
Installing collected packages: RPi.GPIO
Running setup.py install for RPi.GPIO ... error
ERROR: Command errored out with exit status 1:
command: /home/ユーザー名等々/src/servo_test/env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1dejrtne/rpi-gpio_85afa96b80234a438f5c9b6243793098/setup.py'"'"'; file='"'"'/tmp/pip-install-1dejrtne/rpi-gpio_85afa96b80234a438f5c9b6243793098/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-7a9_4klo/install-record.txt --single-version-externally-managed --compile --install-headers /home/ユーザー名等々/src/servo_test/env/include/site/python3.9/RPi.GPIO
cwd: /tmp/pip-install-1dejrtne/rpi-gpio_85afa96b80234a438f5c9b6243793098/
Complete output (27 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-aarch64-3.9
creating build/lib.linux-aarch64-3.9/RPi
copying RPi/init.py -> build/lib.linux-aarch64-3.9/RPi
creating build/lib.linux-aarch64-3.9/RPi/GPIO
copying RPi/GPIO/init.py -> build/lib.linux-aarch64-3.9/RPi/GPIO
running build_ext
building 'RPi._GPIO' extension
creating build/temp.linux-aarch64-3.9
creating build/temp.linux-aarch64-3.9/source
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python3.9-PN012d/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/build/python3.9-PN012d/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/ユーザー名等々/src/servo_test/env/include -I/usr/include/python3.9 -c source/c_gpio.c -o build/temp.linux-aarch64-3.9/source/c_gpio.o
source/c_gpio.c: In function ‘setup’:
source/c_gpio.c:170:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
170 |     if ((uint32_t)gpio_mem % PAGE_SIZE)
|         ^
source/c_gpio.c:171:34: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
171 |         gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);
|                                  ^
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python3.9-PN012d/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/build/python3.9-PN012d/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/ユーザー名等々/src/servo_test/env/include -I/usr/include/python3.9 -c source/common.c -o build/temp.linux-aarch64-3.9/source/common.o
source/common.c:23:10: fatal error: Python.h: No such file or directory
23 | #include "Python.h"
|          ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/aarch64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/ユーザー名等々/src/servo_test/env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1dejrtne/rpi-gpio_85afa96b80234a438f5c9b6243793098/setup.py'"'"'; file='"'"'/tmp/pip-install-1dejrtne/rpi-gpio_85afa96b80234a438f5c9b6243793098/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-7a9_4klo/install-record.txt --single-version-externally-managed --compile --install-headers /home/ユーザー名等々/src/servo_test/env/include/site/python3.9/RPi.GPIO Check the logs for full command output.

仮想環境を利用している状態でpip listとして、何かしらの反応もあるようだしなんでだろうと悩んでいた・・・

解決?

一度仮想環境から抜けてpipをインストールする

sudo apt-get install pip

そしてまた仮想環境に入ってpip installをするとうまく行っているようだった!

もやもや

raspberrypi os liteをダウンロードしたら色々入っていなかったのがトラブルの原因な感じがする!(自分みたいな全くの初心者はデスクトップ環境を使わないとしても、そっちのバージョンのosを入れたのほうがいいのかもね??)

とはいえ、仮想環境に入った状態で、pip listが実行できたのはなんでなのだろうか・・・?わからないことがまだまだ多いですわね・・・

トラブルを通じて成長できるかもしれないけど、自分の場合はその場しのぎの対策を見つけるだけで、「なんでこういう状態になっているの?!」というのを面倒で追求しないので、自分は成長するのが遅いのでしょうね・・・・

おまけ(GPTちゃんによる要約)

/posts/rpi_venv_installrpigpio_error/nahi.png