Coder Perfect

The pg config program could not be located.


I can’t seem to get psycopg2 to work. When I try to pip install psycopg2, I receive the following error:

Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:

    python build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.

Command python egg_info failed with error code 1 in /tmp/pip-build/psycopg2

But the problem is that pg config is indeed on my PATH, and it works fine:

$ which pg_config

I tried adding the pg config path to the setup.cfg file and creating it from the source files I downloaded from their website (, but I got the following error!

Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'

It is, however, ACTUALLY THERE!!!

These blunders perplex me. Could someone please assist me?

By the way, I ran all of the commands using sudo. I’m also running RHEL 5.5.

Asked by user1448207

Solution #1

Postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun) has pg config.

Answered by TilmanBaumann

Solution #2

On Mac OS X, I used the homebrew package manager to remedy the problem.

brew install postgresql

Answered by azalea

Solution #3

Do you have python-dev installed? Install libpq-dev as well if you haven’t previously.

sudo apt-get install libpq-dev python-dev

How to install psycopg2 in a virtual environment (from the article)

Answered by thegauraw

Solution #4

Also available for Mac OS X. I downloaded from, but the problem persisted.

I identified pg config in the guts of that app and added the directory to $PATH.

/Applications/ was the location. So, export PATH=”/Applications/$PATH” worked for me.

Answered by Tayler

Solution #5

With pip or conda, you can install pre-compiled binaries on any platform:

python -m pip install psycopg2-binary


conda install psycopg2

Please note that in production, the psycopg2-binary pypi page suggests building from source:

Use python -m pip install psycopg2 to install the package from sources. Several dependencies (documents) will be required for this process (emphasis mine):

Answered by jakub

Post is based on