我在安装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的人来说,这个解决方案对我来说是有效的:

1)安装postgresql .app:

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

2)然后打开终端并运行这个命令,将上面的{{version}}替换为Postgres的版本号:

导出路径= $路径:/应用程序/ Postgres.app /内容/版本/ {{version}} / bin

e.g.

导出路径= $路径:/应用程序/ Postgres.app /内容/版本/ 9.4 / bin

其他回答

我发现这个页面提供了在我的mac上安装PostgreSQL的最佳说明,pip install命令在之后完美地工作:

https://www.codefellows.org/blog/three-battle-tested-ways-to-install-postgresql

在MAC Mojave上,如果你已经使用brew安装了它,那么就这样做 酿造信息<你的postgres>

它会显示你应该设置的所有环境变量,简单地复制粘贴这些命令,重新启动你的shell,就是这样!

一个简单的解决方法是

pip install psycopg2==2.7.5

pg_config在postgresql-devel中(Debian/Ubuntu中的libpq-dev, Centos/Fedora/Cygwin/Babun中的libpq-devel)。

在Arch Linux上安装python-psycopg2为我解决了这个问题:

pacman -S python-psycopg2