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.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF