‘error: pg_config executable not found’ – 4 Ways to Fix

error: pg_config executable not found solution

When working with Python and PostgreSQL, you might encounter the error pg_config executable not found while installing or using the psycopg2 package. This error occurs because the pg_config executable file is missing from your system Source. This article will guide you through various methods to resolve this error, ensuring a smooth development experience.

What is pg_config?

pg_config is a command-line tool that provides information about the PostgreSQL installation on your system, such as library paths and header files. It is included in the libpq-dev package Source.

How to fix the error: pg_config executable not found.?

1. Install libpq-dev and python-dev

The first step in fixing this error is installing the libpq-dev package, which includes the pg_config executable. If you are using Debian or Ubuntu, you can install libpq-dev and python-dev using the following command:

sudo apt-get install libpq-dev python-dev

On CentOS, Fedora, Cygwin, or Babun, you can install the libpq-devel package using this command:

sudo yum install libpq-devel

Source, Source

2. Use Homebrew on macOS

If you are using macOS, you can install PostgreSQL, including the pg_config executable, using the Homebrew package manager. First, install Homebrew if you haven’t already, and then run the following command:

brew install postgresql

This will install PostgreSQL and the necessary files, fixing the error Source, Source

3. Install psycopg2-binary

If you prefer not to build psycopg2 from source, you can install the pre-compiled psycopg2-binary package using pip or conda:

pip install psycopg2-binary


conda install psycopg2

This will install the pre-compiled psycopg2 package and resolve the error Source.

4. Update your PATH

If you have already installed PostgreSQL and the pg_config executable is present on your system, but the error persists, you may need to add the directory containing pg_config to your PATH environment variable. You can do this by adding the following line to your shell configuration file (e.g., ~/.bashrc or ~/.zshrc):

export PATH="/path/to/pg_config_directory:$PATH"

Replace /path/to/pg_config_directory with the actual directory containing the pg_config executable. After updating your shell configuration file, restart your terminal or run source ~/.bashrc (or source ~/.zshrc) to apply the changes Source.

Conclusion on error: pg_config executable not found.

In this article, we explored various methods to resolve the pg_config executable not found error. By installing the necessary packages and updating your PATH, you should be able to fix this issue and continue working with psycopg2 and PostgreSQL in your Python projects. Always remember to keep your packages up-to-date and ensure that your system’s environment variables are configured correctly to avoid similar issues in the future Source.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top