Error: pg_config executable not found. - How to solve the Python error

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:

  • Get the latest PostgreSQL installation from the official website:
  • Download the relevant installer, either x86 or x64
  • Run the installer and select the relevant development components

MacOS users:

  • For MacOS, you can use either Homebrew or MacPorts as package managers
  • Using Homebrew, open Terminal and run the following command:
brew install postgresql
  • Using MacPorts, open Terminal and run the following command:
sudo port install postgresql

Linux users:

  • On Ubuntu or Debian, open the Terminal and run the command:
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.

Dealing with bugs is πŸ’©, but not with Jam.

Capture bugs fast, in a format that thousands of developers love.
Get Jam for free