Resolving the "externally-managed-environment" Error When Installing frappe-bench on Ubuntu

Hi everyone,

I’m encountering an issue while trying to install frappe-bench on my Ubuntu system using the command sudo pip3 install frappe-bench. The error message I’m receiving is:

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.12/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.

Steps to Resolve the Error

Option 1: Using a Virtual Environment

  1. Install the venv module:
sudo apt install python3-venv
  1. Create a virtual environment :
python3 -m venv frappe-bench-env
  1. Activate the virtual environment:
  • On Linux/macOS:
source frappe-bench-env/bin/activate
  • On Windows:
.\frappe-bench-env\Scripts\activate
  1. Install frappe-bench within the virtual environment:
pip install frappe-bench

Option 2: Using pipx

pipx is a tool for installing and running Python applications in isolated environments.

  1. Install pipx:
sudo apt install pipx
  1. Ensure pipx path is added to your shell profile:
pipx ensurepath
  1. Install frappe-bench using pipx:
pipx install frappe-bench

These methods ensure that the frappe-bench installation does not interfere with your system’s Python packages, avoiding the “externally-managed-environment” error. By using virtual environments or pipx, you can manage your Python packages efficiently and safely.

If anyone has additional tips or alternative solutions, please share them!

Thanks!

This Solution Works For me Also

https://docs.frappe.io/framework/user/en/installation

Read this solution is in last of this page.