Raspberry Pi OS (64) Bookworm

With the advent of Raspberry PI OS Bookworm, Python’s environment is now ‘Externally Managed’. This means when you try to install something using PIP you might receive the following error message:

$ pip install python_widget
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.

Apparently Python Virtual Environments (VENV) are now the standard on Bookworm. You can override this error using --break-system-packages, but this may break your python installation or messing up the operating system. Much better to use virtual enviroments. While trying to learn how to deal with pip and venv, I stumble on the very helpful post: About Python virtual environments.

Its gives simple step-by-step directions one how to setup per-project or per-user python virtual environments. So if you get an error message similar to the one above, take a few minutes to familiarize yourself with venv, it may save you from pulling your hair out.

By Lynx

Born in the 70's. Grew up in Western NY. Happily married, and has 2 children. Lives in Connecticut.

Leave a Reply

Your email address will not be published. Required fields are marked *