Getting error when ' bench init frappe-bench '

anjan@Anjans-MacBook-Air Documents % bench init frappe-bench                                             
WARN: bench is installed in editable mode!

This is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`

$ /opt/homebrew/bin/virtualenv --quiet env -p python3
$ /Users/anjan/Documents/frappe-bench/env/bin/python -m pip install --quiet --upgrade pip
Getting frappe
$ git clone  --depth 1 --origin upstream
Cloning into 'frappe'...
remote: Enumerating objects: 3224, done.
remote: Counting objects: 100% (3224/3224), done.
remote: Compressing objects: 100% (2883/2883), done.
remote: Total 3224 (delta 438), reused 1207 (delta 240), pack-reused 0
Receiving objects: 100% (3224/3224), 16.69 MiB | 10.79 MiB/s, done.
Resolving deltas: 100% (438/438), done.
Installing frappe
$ /Users/anjan/Documents/frappe-bench/env/bin/python -m pip install --quiet --upgrade -e /Users/anjan/Documents/frappe-bench/apps/frappe 
  error: subprocess-exited-with-error
  × python egg_info did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      running egg_info
      creating /private/var/folders/fj/b15dx8s50js3g70fc0y28lsw0000gn/T/pip-pip-egg-info-uf3mk3i9/psycopg2_binary.egg-info
      writing /private/var/folders/fj/b15dx8s50js3g70fc0y28lsw0000gn/T/pip-pip-egg-info-uf3mk3i9/psycopg2_binary.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/fj/b15dx8s50js3g70fc0y28lsw0000gn/T/pip-pip-egg-info-uf3mk3i9/psycopg2_binary.egg-info/dependency_links.txt
      writing top-level names to /private/var/folders/fj/b15dx8s50js3g70fc0y28lsw0000gn/T/pip-pip-egg-info-uf3mk3i9/psycopg2_binary.egg-info/top_level.txt
      writing manifest file '/private/var/folders/fj/b15dx8s50js3g70fc0y28lsw0000gn/T/pip-pip-egg-info-uf3mk3i9/psycopg2_binary.egg-info/SOURCES.txt'
      Error: pg_config executable not found.
      pg_config is required to build psycopg2 from source.  Please add the directory
      containing pg_config to the $PATH or specify the full executable path with the
          python build_ext --pg-config /path/to/pg_config build ...
      or with the pg_config option in 'setup.cfg'.
      If you prefer to avoid building psycopg2 from source, please install the PyPI
      'psycopg2-binary' package instead.
      For further information please check the 'doc/src/install.rst' file (also at
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/bench/commands/", line 70, in init
  File "/opt/homebrew/lib/python3.9/site-packages/bench/utils/", line 95, in wrapper_fn
    return fn(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/bench/utils/", line 78, in init
  File "/opt/homebrew/lib/python3.9/site-packages/bench/", line 371, in get_app
    app.install(verbose=verbose, skip_assets=skip_assets, restart_bench=restart_bench)
  File "/opt/homebrew/lib/python3.9/site-packages/bench/utils/", line 110, in wrapper_fn
    return fn(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/bench/", line 198, in install
  File "/opt/homebrew/lib/python3.9/site-packages/bench/", line 422, in install_app"{bench.python} -m pip install {quiet_flag} --upgrade -e {app_path} {cache_flag}")
  File "/opt/homebrew/lib/python3.9/site-packages/bench/", line 43, in run
    return exec_cmd(cmd, cwd=cwd or self.cwd)
  File "/opt/homebrew/lib/python3.9/site-packages/bench/utils/", line 126, in exec_cmd
    raise CommandFailedError

ERROR: There was a problem while creating frappe-bench
Do you want to rollback these changes? [y/N]: y
INFO: Rolling back Bench "frappe-bench"

@Anjan_Dev please install this

sudo apt install libpq-dev

were you able to find any solution, I am facing a similar issue

uninstalling frappe bench and reinstalling using

sudo -H pip3 install frappe-bench

This worked for me last time

sudo apt-get install python3-dev python3.10-dev python3-setuptools python3-pip python3-distutils