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


当前回答

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

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

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

其他回答

我在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。(我知道这是第六十个答案,但我希望这个答案仍然可以帮助到一些人)。

阿里的解决方案为我工作,但我有麻烦找到bin文件夹的位置。在Mac OS X上找到路径的一个快速方法是打开psql(在顶部菜单栏中有一个快速链接)。这将打开一个单独的终端窗口,在第二行中,Postgres的安装路径将如下所示:

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

您的pg_config文件在bin文件夹中。因此,在安装psycopg2之前,设置pg_config文件的路径:

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

或更新版本:

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

然后安装psycopg2。

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

pacman -S python-psycopg2

对于CentOS/RedHat,确保/etc/alternatives/pgsql-pg_config是一个未断开的符号链接

更新/etc/yum.repos.d / CentOS-Base。回购,[基础]和[更新]部分 添加排除= postgresql *

curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr  
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm

yum install postgresql  
yum install postgresql-devel

PATH=$PATH:/usr/pgsql-9.1/bin/

pip install psycopg2