pg_config executable not found
Solution 1
pg_config
is in postgresql-devel
(libpq-dev
in Debian/Ubuntu, libpq-devel
on Centos/Fedora/Cygwin/Babun.)
Solution 2
On Mac OS X, I solved it using the homebrew package manager
brew install postgresql
Solution 3
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
Solution 4
Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.
I found pg_config
in that app's contents and added the dir to $PATH
.
It was at /Applications/Postgres.app/Contents/Versions/latest/bin
. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
.
Solution 5
You can install pre-compiled binaries on any platform with pip
or conda
:
python -m pip install psycopg2-binary
or
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 aserror: 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 anerror: libpq-fe.h: No such file or directory
you are missing them.- The
pg_config
program: it is usually installed by thelibpq-dev
package but sometimes it is not in aPATH
directory. Having it in thePATH
greatly streamlines the installation, so try runningpg_config --version
: if it returns an error or an unexpected version number then locate the directory containing thepg_config
shipped with the rightlibpq
version (usually/usr/lib/postgresql/X.Y/bin/
) and add it to thePATH
:$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
You only need
pg_config
to compilepsycopg2
, 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 setup.py build $ python setup.py install
Admin
Updated on October 16, 2021Comments
-
Admin over 2 years
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 setup.py build_ext --pg-config /path/to/pg_config build ... or with the pg_config option in 'setup.cfg'. ---------------------------------------- Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2
But the problem is
pg_config
is actually in myPATH
; it runs without any problem:$ which pg_config /usr/pgsql-9.1/bin/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 (http://initd.org/psycopg/) 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.