Bobcares

Quick Steps to Fix “Error: pg_config executable not found”

by | Jan 9, 2022

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.

10 Comments

  1. bee cool

    Sweet!!! you save my life!

    Reply
  2. Shubham Bairagi

    In the Mac M1 I run the above command but still it’s not installing in vartualenv any suggestions will be appreciated.

    Reply
    • Hiba Razak

      Hi,
      Our Experts can help you with the issue, we’ll be happy to talk to you on chat (click on the icon at right-bottom).

      Reply
  3. Nimra Tahir

    while running commands on ubuntu getting this error

    E: Unable to locate package postgresql-dev
    E: Package ‘python-dev’ has no installation candidate

    Reply
    • Hiba Razak

      Hi,
      Please contact our support team via live chat(click on the icon at right-bottom).

      Reply
  4. Shoaib nawaz

    what is solution for windows ?

    Reply
    • Hiba Razak

      Hi,
      Please contact our support through live chat(click on the icon at right-bottom).

      Reply
  5. julieta

    En windows, use python3.11 y se me fue el error y pip 23.2.1

    Reply
  6. Joe

    brew install postgresql worked for me on 2023 Macbook Air with M2 Apple Silicon processor – thank you!

    Reply
    • Hiba Razak

      Hi Joe,
      Thanks for the feedback. We are glad to know that our article was helpful for you 🙂 .

      Reply

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.