Explain Codes LogoExplain Codes Logo

Pg_config executable not found

python
psycopg2
virtualenv
installation
Nikita BarsukovbyNikita Barsukov·Aug 20, 2024
TLDR

To quickly resolve the pg_config not found error, install the libpq-dev package with the command appropriate for your system:

  • Ubuntu: sudo apt install libpq-dev
  • Fedora: sudo dnf install postgresql-devel
  • Mac: brew install postgresql
  • Windows: Add PostgreSQL's bin directory to your PATH.

The pg_config will be installed, and your operations can proceed error-free.

Troubleshooting: extra steps

If you've installed libpq-dev and still face issues, consider:

  • Verifying the pg_config installation with which pg_config or locate pg_config.
  • If you're using a virtual environment, try reinstalling psycopg2.
  • Ensure a C compiler like GCC is installed, as psycopg2 requires compilation.
  • For resolving virtualenv-specific issues, consider the [Psycopg2 Virtualenv Installation](http://web.archive.org/web/20140615091953/http://goshawknest.wordpress.com/2011/02/16/how-to-install-psycopg2-under-virtualenv/) guide.

Post-install inspection checklist

Once the package is installed:

  1. Use pg_config --version to check its accessibility and installation verification.
  2. Ensure pg_config PATH inclusion with export PATH=/path/to/pg_config:$PATH.
  3. If pg_config is elusive, consider setting the path in setup.cfg.

Facing common enemies

While dealing with psycopg2, you may encounter:

  • Python.h missing errors: Ensure Python development headers installation.
  • libpq-fe.h nightmares: Check if PostgreSQL headers are part of libpq-dev.

Rolling with psycopg2

For psycopg2 installation:

  • If you want it quick and easy: pip install psycopg2-binary for the pre-compiled binary.
  • For custom installations: python setup.py build then python setup.py install.