如何查找pg_config路径

Ben*_*Ben 62 python django postgresql macos

在这里完成新手,试图设置Django与ProstgreSQL一起工作.

我正在使用mac osx 10.6.8.我还安装了PostgreSQL 9.3

当我pip install psycopg2在终端运行时,我收到以下错误

Downloading/unpacking psycopg2
  Downloading psycopg2-2.5.2.tar.gz (685kB): 685kB downloaded
  Running setup.py (path:/private/var/folders/A9/A99cs6x0FNusPejCVkYNTE+++TI/-Tmp-/pip_build_bengorman/psycopg2/setup.py) egg_info for package 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'.
    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info/psycopg2.egg-info

writing pip-egg-info/psycopg2.egg-info/PKG-INFO

writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt

writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt

writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

warning: manifest_maker: standard file '-c' not found



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'.
Run Code Online (Sandbox Code Playgroud)

我已经在这个
如何安装psycopg2-with-pip-on-python pg-config-executable-not-found上看了很多帖子

但我不知道如何找到包含pg_config的bin文件夹位置.找到这条路的任何提示?

ely*_*nch 93

我建议你尝试使用Postgres.app.(http://postgresapp.com)通过这种方式,您可以在Mac上轻松打开和关闭Postgres.完成后,.profile通过附加以下内容将Postgres的路径添加到您的文件中:

PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

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

  • 现在位于`/ Applications/Postgres.app/Contents/Versions/9.3/bin`中. (14认同)
  • `export PATH ="/ Applications/Postgres.app/Contents/Versions/latest/bin:$ PATH"`应适用于任何最新版本. (5认同)

小智 32

sudo find / -name "pg_config" -print
Run Code Online (Sandbox Code Playgroud)

我的配置答案是/Library/PostgreSQL/9.1/bin/pg_config(MAC Maverick)


Dan*_*kov 28

Postgres.app最近更新了.现在它将所有二进制文件存储在"Versions"文件夹中

PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

其中9.4 - 版本的PostgreSQL.

  • 不知道为什么这会被贬低,但这是正确的 - 至少在9.3及以上...... (3认同)

cpr*_*res 22

安装自制软件

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
Run Code Online (Sandbox Code Playgroud)

然后安装postgresql

brew install postgresql
Run Code Online (Sandbox Code Playgroud)

给了我这个可爱的输出:

checking for pg_config... yes
Run Code Online (Sandbox Code Playgroud)

啊啊,是的


Afr*_*ave 12

在MacOS X 10.11上安装当前的PostgreSQL应用程序后,这就是pg_config文件所在的位置/Library/PostgreSQL/9.5/bin/pg_config.

然后在终端上:

    $ export PG_HOME=/Library/PostgreSQL/9.5
    $ export PATH=$PATH:$PG_HOME/bin
Run Code Online (Sandbox Code Playgroud)

这会将路径放在您正在使用的终端的.profile中.

在您的环境中(假设您正在使用virtualenv),然后安装psycopg2:

    $ pip install psycopg2
Run Code Online (Sandbox Code Playgroud)

您应该看看之前是否已经下载过:

    Collecting psycopg2
      Using cached psycopg2-2.6.1.tar.gz
    Installing collected packages: psycopg2
      Running setup.py install for psycopg2 ... done
    Successfully installed psycopg2-2.6.1
Run Code Online (Sandbox Code Playgroud)


ber*_*gle 8

这是如何简单地获取路径pg_config

$ which pg_config                 // prints the directory location 
/usr/bin/pg_config
Run Code Online (Sandbox Code Playgroud)


jkd*_*dev 7

总结一下 - PostgreSQL根据版本号和安装方法在不同位置安装其文件(包括其二进制文件或可执行文件).

一些可能性:

/usr/local/bin/
/Library/PostgreSQL/9.2/bin/
/Applications/Postgres93.app/Contents/MacOS/bin/
/Applications/Postgres.app/Contents/Versions/9.3/bin/
Run Code Online (Sandbox Code Playgroud)

难怪人们感到困惑!

另外,如果你的$ PATH环境变量包括到包含可执行文件的目录路径(证实这一点,使用echo $PATH命令行),那么你可以跑which pg_config,which psql等找出该文件所在.


小智 6

Mac 上有同样的问题,您可能需要

酿造安装postgresql

然后你可以运行

pip 安装 psycopg2

brew 将为您解决 PATH 问题

这个解决方案至少对我有用。


rom*_*inm 5

我有完全相同的错误,但我通过brew安装postgreSQL并重新运行原始命令,它完美地工作:

brew安装postgresql