"python setup.py egg_info" failed with error code 1 error running bench init

bench init is failing with this error, and I’m not sure what’s the cause. Can anyone please help me troubleshoot the error?

$ bench init frappe
INFO:bench.utils:virtualenv -q env -p /usr/bin/python
Already using interpreter /usr/bin/python
INFO:bench.utils:env/bin/pip -q install --upgrade pip
INFO:bench.utils:env/bin/pip -q install wheel
INFO:bench.utils:env/bin/pip -q install six
INFO:bench.utils:env/bin/pip -q install -e git+https://github.com/frappe/python-pdfkit.git#egg=pdfkit
INFO:bench.app:getting app frappe
INFO:bench.utils:git clone https://github.com/frappe/frappe.git   --origin upstream
Cloning into 'frappe'...
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 160689 (delta 11), reused 16 (delta 3), pack-reused 160637
Receiving objects: 100% (160689/160689), 178.98 MiB | 1.28 MiB/s, done.
Resolving deltas: 100% (122269/122269), done.
Checking out files: 100% (2291/2291), done.
('installing', u'frappe')
INFO:bench.app:installing frappe
INFO:bench.utils:frappe/env/bin/pip install -q  -e frappe/apps/frappe 
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-VfXOHW/psycopg2/
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/bench/cli.py", line 40, in cli
    bench_command()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/bench/commands/make.py", line 30, in init
    python               = python)
  File "/usr/local/lib/python2.7/dist-packages/bench/utils.py", line 75, in init
    get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose)
  File "/usr/local/lib/python2.7/dist-packages/bench/app.py", line 135, in get_app
    install_app(app=app_name, bench_path=bench_path, verbose=verbose)
  File "/usr/local/lib/python2.7/dist-packages/bench/app.py", line 179, in install_app
    find_links=find_links))
  File "/usr/local/lib/python2.7/dist-packages/bench/utils.py", line 159, in exec_cmd
    raise CommandFailedError(cmd)
bench.utils.CommandFailedError: frappe/env/bin/pip install -q  -e frappe/apps/frappe

My Debian system was missing libpq-dev, and the error was thrown during installation of psycopg2 which depends on it, although I’m not sure why bench needs them.

It is often useful to include the environment that you are trying to install on , and the version of ERPNext. Is this a new bench installation or has it been used successfully in the past?

More details will help people help you.