I was trying to install postgres for a tutorial, but pip
gives me error:
pip install psycopg
A snip of error I get:
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'.
Where is pg_config
in my virtualenv? How to configure it? I'm using virtualenv because I do not want a system-wide installation of postgres.
In addition to the answers provided by @bkev and @andi, according to the documentation on Postgres.app, you should add the following to your bash_profile on Mac:
Note that, there is no hard-coded version number. I wanted to add this as a comment to above answers, but I don't have enough rep for this.
If you don't have to use the
psycopg
driver specifically, switch to thepg8000
driver. It's pure Python and less finicky.On Mac, the solution is to install
postgresql
:On CentOS, the solution is to install
postgresql-devel
:pg_config
is inpostgresql-devel
packageMine was located in /Library/PostgreSQL/9.4/bin
This error is caused when the build tools can't find the Postgresql libraries.
Often it's required to instruct psycopg2 how to find the pg_config binary, you can:
add the path to pg_config in your shell path (/usr/local/pgsql/bin/)
or edit the setup.cfg file in the psycopg2 source folder and provide the full path to pg_config on the line that starts with pg_config=
locate pg_config
to find out where it resides, or simply typewhich pg_config
and it should tell you the path.Less often the error comes from not having postgresql installed on your system. If so, download and build postgres, or download a pre-built psycopg2 binary for OS X.
For
OS X El Captain (10.11.6)
+brew
+virtualenv
+PostgreSQL 9.5
:After installing
PostgreSQL 9.5
:Open your terminal and execute: