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 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 that pg config is indeed on my PATH, and it works fine:
$ which pg_config /usr/pgsql-9.1/bin/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 (http://initd.org/psycopg/), 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
Postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun) has pg config.
Answered by TilmanBaumann
On Mac OS X, I used the homebrew package manager to remedy the problem.
brew install postgresql
Answered by azalea
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
Also available for Mac OS X. I downloaded Postgress.app from http://postgresapp.com/, but the problem persisted.
I identified pg config in the guts of that app and added the directory to $PATH.
/Applications/Postgres.app/Contents/Versions/latest/bin was the location. So, export PATH=”/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH” worked for me.
Answered by Tayler
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 https://stackoverflow.com/questions/11618898/pg-config-executable-not-found