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


当前回答

我遇到这个问题是因为我没有安装postgres。如果你有brew安装运行

brew install postgresql

这应该可以解决问题。

其他回答

刚刚解决了问题在Cent OS 7:

export PATH=$PATH:/usr/pgsql-9.5/bin

确保你的PostgreSql版本与上面的正确版本匹配。

更新/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

我建议你尝试使用postgresp。app。(http://postgresapp.com)通过这种方式,你可以很容易地在你的Mac上打开和关闭Postgres。一旦你这样做了,添加到Postgres的路径到你的.profile文件,通过追加以下内容:

路径= " /应用程序/ Postgres.app /内容/版本/最近/ bin:美元路径”

只有在将Postgres添加到路径后,才能尝试在虚拟环境中(使用pip)或在全局站点包中安装psycopg2。

如果你最近更新了python或更改了默认的python(比如从3.6到3.8)。下面的代码

sudo apt-get install python-dev   OR    sudo apt-get install python3-dev

将安装/工作于以前的python版本。

因此,如果您希望此命令适用于最近更新/更改的python版本,请尝试在以下命令中提到特定版本,如python3.8

sudo apt-get install python3.8-dev  

尝试以下内容

pip install wheel
export PATH=/path/to/compiled/postgresql/bin:"$PATH"
sudo apt-get install libpq-dev
sudo apt-get install python3.x-dev    **Change x with your version, eg python3.8**
pip install psycopg2-binary
pip install psycopg2

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

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