RasberryPiにおける外部管理環境の制限
外部管理環境
macでPythonのライブラリをインストールする時に使用しているpipinstaller.shなるものをRasberryPiに転送して実行したところ、以下のようなエラーが出ました。
$sh ./pipinstaller.sh
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
For more information visit http://rptl.io/venv
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
CVSSの目的
エラー内容はPEP 668 による「externally-managed-environment」(外部管理環境)の制限が原因とのこと。
最近の Debian / Raspberry Pi OS / Ubuntu では、システムの Python 環境に直接 pip でパッケージを入れるのを禁止していて、代わりに以下の方法を取る必要があります。
# venv モジュールをインストール(必要なら)
sudo apt install python3-venv -y
# 仮想環境を作成
python3 -m venv venv
# 有効化
source venv/bin/activate
評価基準
この状態でpipコマンドを使用したら無事インストールすることができました。
pipでインストールしたライブラリは仮想環境内でしか使用できないため、python実行時も仮想環境で動かす必要があります。
コメント
コメントを投稿