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 my PATH
; 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.
This is what worked for me on CentOS, first install:
On Ubuntu just use the equivilent apt-get packages.
And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:
Make sure to include the correct path. Thats all :)
Try to add it to PATH:
On Windows, You may want to install the Windows port of Psycopg, which is recommended in psycopg's documentation.
On Linux Mint
sudo apt-get install libpq-dev
worked for me.I found that this page provided the best instructions for installing PostgreSQL on my mac and that the pip install command worked perfectly afterwards:
https://www.codefellows.org/blog/three-battle-tested-ways-to-install-postgresql
Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:
1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.
2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:
so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:
This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.
I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.