pg_config executable not found


I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:

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 pg_config is actually in my PATH; it runs without any problem:

$ which pg_config

I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website ( and I get the following error message!

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

But it is actually THERE!!!

I am baffled by these errors. Can anyone help please?

By the way, I sudo all the commands. Also I am on RHEL 5.5.

Answer rating: 1029

pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)

Answer rating: 538

On Mac OS X, I solved it using the homebrew package manager

brew install postgresql

Answer rating: 298

Have you installed python-dev? If you already have, try also installing libpq-dev

sudo apt-get install libpq-dev python-dev

From the article: How to install psycopg2 under virtualenv

Answer rating: 62

You can install pre-compiled binaries on any platform with pip or conda:

python -m pip install psycopg2-binary


conda install psycopg2

Please be advised that the psycopg2-binary pypi page recommends building from source in production:

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources

To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):

  • A C compiler.
  • The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
  • The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
  • The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH:
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH

You only need pg_config to compile psycopg2, not for its regular usage.

Once everything is in place it’s just a matter of running the standard:

$ pip install psycopg2

or, from the directory containing the source code:

$ python build
$ python install