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


当前回答

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

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

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

其他回答

如果你试图在你的虚拟环境中添加psycopg2依赖项,它将允许你的python项目连接到你的docker或kubernetes pod,在你的Mac上单独运行postgresql,并且不真正有兴趣在Mac上安装postgresql,只是为了获得pg_config,下面是你要做的:

按照pipenv安装错误输出中的建议安装psycopg2_binary,一切都会正常工作。

尝试将其添加到PATH:

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

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

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

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

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

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

一个简单的解决方法是

pip install psycopg2==2.7.5

在安装psycopg2之前,需要升级pip。使用这个命令

pip install --upgrade pip