我在安装psycopg2时遇到了麻烦。当我尝试pip安装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

但问题是pg_config实际上在我的PATH中;它运行起来没有任何问题:

$ which pg_config
/usr/pgsql-9.1/bin/pg_config

我尝试将pg_config路径添加到setup.cfg文件中,并使用我从他们的网站(http://initd.org/psycopg/)下载的源文件构建它,我得到了以下错误消息!

Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'

但它确实在那里!!

我对这些错误感到困惑。有人能帮忙吗?

顺便说一下,我sudo所有的命令。而且我使用的是RHEL 5.5。


当前回答

这里,为了OS X的完整性:如果你从MacPorts安装PostgreSQL, pg_config将在/opt/local/lib/postgresql94/bin/pg_config。

当你安装MacPorts时,它已经将/opt/local/bin添加到你的PATH中。

所以,这将解决问题: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config . sh /opt/local/bin/pg_config . sh

现在pip install psycopg2将能够毫无问题地运行pg_config。

其他回答

你应该在Ubuntu上添加Postgres中使用的python需求。运行:

sudo apt-get install libpq-dev python-dev

这里,为了OS X的完整性:如果你从MacPorts安装PostgreSQL, pg_config将在/opt/local/lib/postgresql94/bin/pg_config。

当你安装MacPorts时,它已经将/opt/local/bin添加到你的PATH中。

所以,这将解决问题: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config . sh /opt/local/bin/pg_config . sh

现在pip install psycopg2将能够毫无问题地运行pg_config。

apt-get build-dep python-psycopg2

对于mac用户,扩展路径变量以包含PostgreSQL,如export path =$ path:/Library/PostgreSQL/12/bin。

在MacOS上,最简单的解决方案是将正确的二进制文件进行符号链接,即在Postgres包下。

sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config

这是相当无害的,如果需要,所有应用程序都可以在系统范围内使用它。