在Mac虚拟机上安装psycopg2时出现问题:找不到pg_config可执行文件



我想在Django项目中使用postgresql,为此我需要在我的virtualenv中安装psycopg2。我已经安装了Postgresql12.2。然而,当我运行pip install psycopg2时,我会得到以下错误:

Error: pg_config executable not found.
pg_config is required to build psycopg2 from source.  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'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).

我已经在/Library/PostgreSQL/12/bin/pg_config找到了pg_config可执行文件,但当我尝试使用PATH="/Library/PostgreSQL/12/bin/pg_config:$PATH"将其添加到PATH变量时,不会显示成功或错误消息。我以前从未使用过PATH变量,所以我不确定这样做是否正确。当我尝试运行which pg_config时,它仍然显示"未找到pg_config",当我再次尝试安装psycopg2时,它显示相同的错误消息。

有人能帮我解决这个问题吗?

两个选项

  1. 使用brew:安装POSTGRESQL

    brew安装postgresql

  1. 在您的python虚拟环境中安装psycopg2-binary

    pip安装psycopg2二进制

最新更新