我在安装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试图将其作为依赖的一部分安装时,我在dockerizing应用程序时遇到了这个问题,为了解决这个问题,我对requirements.txt使用了这个设置,首先安装二进制文件,然后Django不再尝试安装它: psycopg2-binary django gunicorn

其他回答

尝试将其添加到PATH:

PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2

使用postgresql-devel for redhat/ fedora系列解决了这个问题。

Yum安装postgresql-devel

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

brew install postgresql

以下步骤为我解决了这个问题(ubuntu 18.04)

安装postgres(如果没有安装请参考) 安装libpq-dev

Sudo apt-get安装libpq-dev

我通过运行以下命令修复了这个问题。

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2

参考资料:https://stackoverflow.com/a/39800677/4270698