Home > Enterprise >  Cannot find pg_config executable
Cannot find pg_config executable

Time:10-25

Having no idea what pg_config is, I searched online and it seems to be part of or connected to PostgreSQL. I don't have or use that though and never have but I suspect that I may be getting this because I recently started using azure libraries in Python (I never had this problem before). Here is one of the error messages:

WARNING: Discarding https://files.pythonhosted.org/packages/aa/8a/7c80e7e44fb1b4277e89bd9ca509aefdd4dd1b2c547c6f293afe9f7ffd04/psycopg2-2.9.1.tar.gz#sha256=de5303a6f1d0a7a34b9d40e4d3bef684ccc44a49bbe3eb85e3c0bffb4a131b7c (from https://pypi.org/simple/psycopg2/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Using cached psycopg2-2.9.tar.gz (379 kB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\E\AppData\Local\Programs\Python\Python310\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\E\\AppData\\Local\\Temp\\pip-install-q50_w0n5\\psycopg2_b3e7f5e155154965bfc0d5340d85b1ff\\setup.py'"'"'; __file__='"'"'C:\\Users\\E\\AppData\\Local\\Temp\\pip-install-q50_w0n5\\psycopg2_b3e7f5e155154965bfc0d5340d85b1ff\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\E\AppData\Local\Temp\pip-pip-egg-info-ufqtnd89'
       cwd: C:\Users\E\AppData\Local\Temp\pip-install-q50_w0n5\psycopg2_b3e7f5e155154965bfc0d5340d85b1ff\
  Complete output (23 lines):
  running egg_info
  creating C:\Users\E\AppData\Local\Temp\pip-pip-egg-info-ufqtnd89\psycopg2.egg-info
  writing C:\Users\E\AppData\Local\Temp\pip-pip-egg-info-ufqtnd89\psycopg2.egg-info\PKG-INFO
  writing dependency_links to C:\Users\E\AppData\Local\Temp\pip-pip-egg-info-ufqtnd89\psycopg2.egg-info\dependency_links.txt
  writing top-level names to C:\Users\E\AppData\Local\Temp\pip-pip-egg-info-ufqtnd89\psycopg2.egg-info\top_level.txt
  writing manifest file 'C:\Users\E\AppData\Local\Temp\pip-pip-egg-info-ufqtnd89\psycopg2.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
  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>).

It seems like the problem isn't with the path but rather just that I don't have pg_config at all. Searching online didn't help; the suggestions I found were:

  • upgrade pip
  • brew install postgresql (seems to be just for macs???)
  • pip install psycopg2-binary
  • run which pg_config run
  • whereis pg_config (also tried where)

None of it worked. Any command starting with pg_config says that it is an unrecognized command.

CodePudding user response:

Install PostgreSQL. When installing from packages, make sure to install the development package that contains pg_config, PGXS and the C headers.

You may need to put the PostgreSQL binary directory on the PATH:

export PATH=/usr/pgsql-14/bin:$PATH

(Of course you have to use the correct path.)

  • Related