我在安装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。


当前回答

在Gentoo上,您必须执行以下操作

# Install postgresql client libraries
sudo emerge postgresql-base

其他回答

MAC用户

通过HomeBrew添加postgresql包后,可能需要添加openssl路径变量-

出口LIBRARY_PATH = $ LIBRARY_PATH: / usr /地方/ opt / openssl / lib /

然后,您可以再次安装psycopg2包,它应该可以工作。

我很确定你也经历过和我一样的“问题”,因此我将为你提供一个极其简单的解决方案……

在你的例子中,你需要添加到$ path(或作为命令参数)的实际路径是:

/usr/pgsql-9.1/bin/pg_config

not

/usr/pgsql-9.1/bin

例如,如果你随后运行python setup.py脚本,你会像这样运行它:

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

也许太晚了,但仍然是最简单的解决办法。

后来编辑:

在进一步的测试中,我发现如果最初在表单中添加路径到pg_config

/usr/pgsql-9.1/bin

(...../bin后面没有/pg_config)并运行PIP install命令,它将工作。

然而,如果你决定按照指示运行python setup.py,你必须在.....之后用/pg_config指定路径/ bin。

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

在Mac OS X上,我使用自制包管理器解决了这个问题

brew install postgresql

我在Oracle Linux 7.9上安装这个库时遇到了很大的问题。无论我在做什么,我都无法通过pip安装psycopg2。所以我决定通过yum使用以下命令安装它:

yum install http://mirror.centos.org/centos/7/os/x86_64/Packages/python-psycopg2-2.5.1-4.el7.x86_64.rpm

通过这个命令安装psycopg2,我可以通过ansible创建postgres用户,DB。(我知道这是第六十个答案,但我希望这个答案仍然可以帮助到一些人)。

这是我在CentOS上使用的方法,首先安装:

sudo yum install postgresql postgresql-devel python-devel

在Ubuntu上使用等价的apt-get包即可。

sudo apt-get install postgresql postgresql-dev python-dev

现在在pip install中包含到你的postgresql二进制目录的路径,这应该适用于Debain或基于RHEL的Linux:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

确保包含正确的路径。就这些。