0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「RaspberryPi で pip をインストール」
https://qiita.com/nanbuwks/items/315f4281cbad51c73510
のときは、 Debian 系の pip のクセを書いたのだけれど、最近は結構めんどくさくなっているらしい。

環境

  • Debian Testing ( Debian 13 : 2024/07/06 時点 )
  • pip ( OS ディストリビューション版 )

(2024/7/11追記:以下でも同様であることを確認しました)

  • Raspberry Pi OS Lite (2024-07-04-raspios-bookworm-armhf-lite.img.xz)

(2025/2/07追記:以下でも同様であることを確認しました)

  • Ubuntu 24.04 LTS
# apt install python3-pip

pip でエラー

$ pip3 install python3-PySimpleGUI
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.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

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.

最近の Debian系のOSディストリビューション版 pip を使うとこのような挙動になるらしいです。

cf.,「ラズパイに怒られた話【error: externally-managed-environment】」
https://qiita.com/kei_tnk/items/f80f552185ce16530133

推奨のやり方

OS ディストリビューションパッケージの Python モジュールを使う

$ apt-cache search python3-hogehoge

のようにしてパッケージを探し、インストールします。

仮想環境を使うやり方

エラーメッセージに書いているように、仮想環境を作り

$ python3 -m venv path/to/venv

仮想環境に入ります。

$source path/to/venv

その中で pip を行います。

$ python3 -m pip install パッケージ

cf.,「Python environment best practices on Debian-based distros - 7.7」
https://developer.parrot.com/docs/olympe/pip_on_debian_based_distros.html

ppa や deb パッケージを使用

パッケージ提供元が用意していれば。

掟破り

Debian パッケージにもないし、システムにインストールする必要がある場合は、強制的に pip を使ってインストールします。

--break-system-package オプションを使います。

# pip install --break-system-package  PySimpleGUI
Collecting PySimpleGUI
  Downloading PySimpleGUI-5.0.6-py3-none-any.whl.metadata (6.6 kB)
Collecting rsa (from PySimpleGUI)
  Downloading rsa-4.9-py3-none-any.whl.metadata (4.2 kB)
Collecting pyasn1>=0.1.3 (from rsa->PySimpleGUI)
  Downloading pyasn1-0.6.0-py2.py3-none-any.whl.metadata (8.3 kB)
Downloading PySimpleGUI-5.0.6-py3-none-any.whl (1.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 19.3 MB/s eta 0:00:00
Downloading rsa-4.9-py3-none-any.whl (34 kB)
Downloading pyasn1-0.6.0-py2.py3-none-any.whl (85 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.3/85.3 kB 2.8 MB/s eta 0:00:00
Installing collected packages: pyasn1, rsa, PySimpleGUI
Successfully installed PySimpleGUI-5.0.6 pyasn1-0.6.0 rsa-4.9
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?