Fixing "pg_config Executable Not Found" Error in Python | Step-by-Step Guide

Whenever you're trying to install the package Psycopg2, the PostgreSQL database adapter created for the Python language, you might run into a familiar error:

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

Luckily, this is a pretty easy to fix error and below we will explain how to solve the "pg_config executable not found" error on Windows, Mac and Linux. Let's dig it!

Understanding the "pg_config executable not found" error

You will run into this error message when a Python package installation needs the PostgreSQL development libraries and headers. The components are essential for compiling and linking the required files during the installation process.

To solve the "pg_config executable not found" error, here's what you need to do for each platform.

Windows users:

MacOS users:

brew install postgresql
sudo port install postgresql

Linux users:

sudo apt-get install libpq-dev

Once you have installed the required PostgreSQL dev libraries and headers, you can proceed with reinstalling the Python package that caused the initial issue. This time, the installation should successfully locate the required "pg_config" executable and complete it fully.