I have issues while installing frappe bench

hi guys, I was trying to install frappe bench and I did install all of the Packages required but when I started install frappe bench using these commands ,

sudo -H pip3 install frappe-bench

bench --version
marwan@marwan-Dell-G15-5510:~/Frappe$ sudo -H pip3 install frappe-bench

bench --version
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.
Command 'bench' not found, did you mean:
  command 'dbench' from deb dbench (4.0-2.1)
  command 'tbench' from deb dbench (4.0-2.1)
Try: sudo apt install <deb name>

this error shows up idk what I did wrong !!
thanks for helping

Can you please share all the steps you followed to install Bench?

Are you following the Frappe documentation?
https://frappeframework.com/docs/user/en/installation#install-bench-cli

Hi MarwanRashwan

Sounds like you’re using python 3:12 - but an installation method dating to python 3.10. Because Python 3 isn’t backwards compatible with earlier versions - starting in 3.11 they required a venv to be created before doing things like ```
sudo pip3 install frappe-bench


For a very effective workaround - try this:
sudo python3 -m pip config --global set global.break-system-packages true

And then try the install of frappe-bench again.

The system prevents global Python installations to avoid conflicts with system-managed packages (OS wide packages). It does so to protect your OS from breaking dependencies.

Solution: Use virtual environment.

Create a virtual environment with
python3 -m venv venv in your project folder.

Then activate it with source venv/bin/activate.

Inside the environment, run pip install frappe-bench to safely set up the bench.

Hi Jinish

Does the method I use (simply to break-system-packages) a seriously bad idea for production?

Is pipx a good option for someone not used to working with virtual environments?

Apologies for the method I recommended.

I can’t be sure of the intensity as how bad an idea this actually would be. But here is something from PEP for your reference - PEP 668 – Marking Python base environments as “externally managed” | peps.python.org

You can imagine if you use sudo and install a package on the OS for bench, and if bench and one of the system applications are using the same library, this could be an issue, right? - change of version, breaking changes, etc.