Wondering how to resolve Error: pg_config executable not found? We can help you. Today, let’s take a look at how our Support Team help a customer  deal with this error. At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.

Overview
  1. How to resolve Error: pg_config executable not found?
  2. Causes & Solutions

How to resolve Error: pg_config executable not found?

Typically, error looks as shown below:

Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH

Today, let us see the different methods followed by our Support Techs to resolve this error.

Causes & Solutions

Cause 1

Issues with the necessary packages

Solution 1

i. First of all we need is to install libpq-dev and python-dev  using the below command:

sudo apt-get install libpq-dev python-dev

ii. Then, we can run pip install psycopg2 this command.

Just run this command to install above two mentioned packages.

iii. If you face Python.h: No such file or directory this error then just install python3-dev

Cause 2

Issues with Postgresql in MacOS

Solution 2

On macOS just run below command with the homebrew package manager.

brew install postgresql
Cause 3

Postgresql issues in Linux distributions

Solution 3

For CentOS, first install

sudo yum install postgresql postgresql-devel python-devel

For Ubuntu just use the equivilent apt-get packages.

sudo apt-get install postgresql postgresql-dev python-dev

Then, make sure to include the correct path.

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Cause 4
pg_config
isn’t located

Solution 4

The pg_config tool is usually installed with PostgreSQL, but it may not be in the system’s PATH, making it hard to find. We need to locate pg_config on the system, which is often found in these locations:

On Linux: /usr/pgsql-/bin/pg_config

And on macOS: /usr/local/pgsql/bin/pg_config

On Windows: C:\Program Files\PostgreSQL\\bin\pg_config.exe

Cause 5

PATH Environment Variable Not Updated

Solution 5

Add the directory containing pg_config to the system’s PATH so Python can find it when installing psycopg2.

On Linux and macOS: Edit ~/.bashrc or ~/.bash_profile and add:

export PATH=$PATH:/path/to/pg_config

On Windows: Use Control Panel to edit environment variables, or run this in Command Prompt:

setx PATH “%PATH%;C:\path\to\pg_config” “`”

Cause 6

Missing Modules

Solution 6

If PostgreSQL 13 is installed at C:\Program Files\PostgreSQL\13\bin\pg_config.exe on your Windows system, fix the issue by running these commands in Command Prompt:

setx PATH “%PATH%;C:\Program Files\PostgreSQL\13\bin” pip install psycopg2 “`” — This version maintains clarity while focusing on the essential steps.

[Need a solution to another query? We are just a click away.]

Conclusion

The “Error: pg_config executable not found” typically occurs when installing PostgreSQL-related packages like psycopg2 because the system cannot locate the pg_config tool.

Today, we saw steps followed by our Support Engineers in order to resolve Error: pg_config executable not found.