python - tool - pg_config executable not found

setup exe the program pg_config is required but it could not be found (18)

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.

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

sudo apt-get install libpq-dev works for me on Ubuntu 15.4

Also on OSX. Installed from but had the same issue.

I found pg_config in that app's contents and added the dir to $PATH.

It was at /Applications/ So this worked: export PATH="/Applications/$PATH".

For those running OS X, this solution worked for me:

1) Install

2) Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:

export PATH=$PATH:/Applications/{{version}}/bin


export PATH=$PATH:/Applications/

Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.

When you installed MacPorts, it already added /opt/local/bin to your PATH.

So, this will fix the problem: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config

Now pip install psycopg2 will be able to run pg_config without issues.

I am pretty sure you've experienced the same "problem" i did, therefore I'll offer you the extremely easy solution...

In your case, the actual path that you need to add to $PATH (or as a command param) is:




E.g. if you run the python script afterwards, you would run it like this:

python build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

Probably too late, but still the easiest solution.


Under further test I found out that if you initially add the path to pg_config in the form


(without /pg_config after ...../bin) and run the pip install command it will work.

However, if you then decide to follow the indication to run python, you will have to specify the path with /pg_config after ...../bin, i.e.

python build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

Installing python-psycopg2 solved it for me on Arch Linux:

pacman -S python-psycopg2

Just solved the problem in Cent OS 7 by:

export PATH=$PATH:/usr/pgsql-9.5/bin

make sure your PostgreSql version matches the right version above.

On Gentoo You have to execute the following

# Install postgresql client libraries
sudo emerge postgresql-base

On Linux Mint sudo apt-get install libpq-dev worked for me.

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

brew install postgresql

This is how I managed to install psycopg2

$ wget
$ tar -xzf psycopg2-2.5.3.tar.gz
$ cd psycopg2-2.5.3
$ python install

This is what worked for me on CentOS, first install:

sudo yum install postgresql postgresql-devel python-devel

On Ubuntu just use the equivilent apt-get packages.

sudo apt-get install postgresql postgresql-dev python-dev

And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

Make sure to include the correct path. Thats all :)

Try to add it to PATH:

PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2

UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*

curl -O  
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm

yum install postgresql  
yum install postgresql-devel


pip install psycopg2

for CentOS/RedHat make sure that /etc/alternatives/pgsql-pg_config is a non-broken symlink

sudo yum install postgresql-devel (centos6X)

pip install psycopg2==2.5.2