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


当前回答

对于任何在Django应用程序中遇到这个问题并将其部署到AWS的人来说,本教程中描述的方法对我来说是有效的:https://realpython.com/deploying-a-django-app-and-postgresql-to-aws-elastic-beanstalk/

下面是作者对出现以下错误的解释:

Error: pg_config executable not found.

问题是我们试图安装psycopy2 (Postgres Python绑定),但我们还需要安装Postgres客户端驱动程序。因为默认情况下没有安装它们,所以我们需要先安装它们。 Eb将从名为“。”的文件夹中读取自定义的。config文件。Ebextensions”在项目的根级别。这些.config文件允许您安装包,运行任意命令和/或设置环境变量。文件中的。ebextensions”目录应该符合JSON或YAML语法,并按字母顺序执行。 首先要做的是安装一些包,以便pip install命令能够成功完成。为此,让我们创建一个名为.ebextensions/01_packages.config的文件:

packages:
  yum:
    git: []
    postgresql93-devel: []
    libjpeg-turbo-devel: []

EC2实例运行Redhat版本的Amazon Linux,因此我们可以使用yum来安装所需的包。现在,我们只安装三个包——git、Postgres客户端和Pillow的libjpeg。

其他回答

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

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

# Install postgresql client libraries
sudo emerge postgresql-base

那些在macOS Catalina上使用zsh shell并安装了postgres应用程序的用户:

打开~/。ZSHRC文件,并添加以下行:

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

然后关闭你所有的终端,重新打开,你的问题就解决了。

如果您不想关闭终端,只需输入source ~/。ZSHRC在任何你想继续工作的终端上。

同样在OSX上。安装postgres。应用程序从http://postgresapp.com/,但有同样的问题。

我在该应用程序的内容中找到了pg_config,并将dir添加到$PATH。

它在/Applications/ postgress .app/Contents/Versions/latest/bin。export PATH="/Applications/ postgress .app/Contents/Versions/latest/bin:$PATH"。

这里,为了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。