unitedstates / congressional-record

A parser for the Congressional Record.
Other
128 stars 40 forks source link

pg_config executable not found. #49

Closed jiaminlim closed 1 year ago

jiaminlim commented 1 year ago

git clone https://github.com/unitedstates/congressional-record.git cd congressional-record python3 -m venv .venv .venv/bin/python -m pip install -e . .venv/bin/python -m congressionalrecord.cli -h

The fourth line above yields the following:

 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
      option:

          python setup.py 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
      <https://www.psycopg.org/docs/install.html>).

      [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.

[notice] A new release of pip available: 22.2.1 -> 22.3.1
[notice] To update, run: python -m pip install --upgrade pip

Based on the above, I installed the 'psycopg2-binary' package using pip install, but I reran the fourth line and am getting the same error.

Then when running the 5th line - I get this error:

Traceback (most recent call last):
  File "/Users/jiaminlim/miniforge3/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/Users/jiaminlim/miniforge3/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/Users/jiaminlim/congressional-record/congressionalrecord/__init__.py", line 2, in <module>
    VERSION = pkg_resources.require("congressionalrecord")[0].version
  File "/Users/jiaminlim/congressional-record/.venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 909, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/Users/jiaminlim/congressional-record/.venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 795, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'congressionalrecord' distribution was not found and is required by the application

Any advice/guidance would be much appreciated.

mw3i commented 1 year ago

I had the same error on Ubuntu, and was able to fix by first doing:

sudo apt-get install libpq-dev
sudo ln -s /bin/gcc /bin/gcc-5

After that, .venv/bin/python -m pip install -e . installed everything correctly for me.

So, might be worth trying that. (I got that solution somewhere on stackoverflow; apologies to the unnamed user I'm failing to credit)

nclarkjudd commented 1 year ago

This sounds like the kind of thing that happens when pip tries to compile psycopg2 for you from source, which you can also solve by installing the binary which is in pip as psycopg2[binary]

EG:

source .venv/bin/activate
pip install psycopg2[binary]