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:02

This is how I managed to install psycopg2

$ wget http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.3.tar.gz
$ tar -xzf psycopg2-2.5.3.tar.gz
$ cd psycopg2-2.5.3
$ python setup.py install
查看更多
对你真心纯属浪费
3楼-- · 2019-01-04 05:02

I am pretty sure you've experienced the same "problem" i did, therefore I'll offer you the extremely easy solution...

In your case, the actual path that you need to add to $PATH (or as a command param) is:

/usr/pgsql-9.1/bin/pg_config

not

/usr/pgsql-9.1/bin

E.g. if you run the python setup.py script afterwards, you would run it like this:

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

Probably too late, but still the easiest solution.

LATER EDIT:

Under further test I found out that if you initially add the path to pg_config in the form

/usr/pgsql-9.1/bin

(without /pg_config after ...../bin) and run the pip install command it will work.

However, if you then decide to follow the indication to run python setup.py, you will have to specify the path with /pg_config after ...../bin, i.e.

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-04 05:04

You need to upgrade your pip before installing psycopg2. Use this command

pip install --upgrade pip
查看更多
一夜七次
5楼-- · 2019-01-04 05:04

Just solved the problem in Cent OS 7 by:

export PATH=$PATH:/usr/pgsql-9.5/bin

make sure your PostgreSql version matches the right version above.

查看更多
迷人小祖宗
6楼-- · 2019-01-04 05:04

Installing python-psycopg2 solved it for me on Arch Linux:

pacman -S python-psycopg2
查看更多
等我变得足够好
7楼-- · 2019-01-04 05:06

On Mac OS X and If you are using Postgres App (http://postgresapp.com/):

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

No need to specify version of Postgres in this command. It will be always pointed to latest.

and do

pip install psycopg2

P.S: If Changes doesn't reflect you may need to restart the Terminal/Command prompt

Source

查看更多
登录 后发表回答