pg_config executable not found

2019-01-04 04:22发布

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.

27条回答
地球回转人心会变
2楼-- · 2019-01-04 05:14

Ali's solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there's a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:

My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;

Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:

PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/

or for newer version:

PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

Then install psycopg2.

查看更多
冷血范
3楼-- · 2019-01-04 05:16

sudo yum install postgresql-devel (centos6X)

pip install psycopg2==2.5.2

查看更多
三岁会撩人
4楼-- · 2019-01-04 05:19

This works for me:

sudo apt-get install libpq-dev python-dev
查看更多
一夜七次
5楼-- · 2019-01-04 05:20

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

1) Install Postgres.app:

http://www.postgresql.org/download/macosx/

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

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin

e.g.

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin

查看更多
倾城 Initia
6楼-- · 2019-01-04 05:24

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

查看更多
Fickle 薄情
7楼-- · 2019-01-04 05:24
apt-get build-dep python-psycopg2
查看更多
登录 后发表回答