如何findpg_configpath

在这里完成新手,试图设置Django与ProstgreSQL合作。

我正在使用mac osx 10.6.8。 我也安装了PostgreSQL 9.3

当我在terminal中运行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'. 

我已经看到了这个post的数目
如何安装的-psycopg2-与点子上,python
PG-configuration可执行未find

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

我build议您尝试使用Postgres.app。 ( http://postgresapp.com )通过这种方式,您可以轻松地在Mac上打开和closuresPostgres。 一旦完成,通过追加以下内容将Postgrespath添加到.profile文件中:

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

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

Postgres.app最近更新了。 现在它将所有的二进制文件存储在“版本”文件夹中

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

其中9.4 – PostgreSQL的版本。

 sudo find / -name "pg_config" -print 

答案是/Library/PostgreSQL/9.1/bin/pg_config在我的configuration(MAC Maverick)

安装自制软件

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

然后安装postgresql

 brew install postgresql 

给了我这个可爱的输出:

 checking for pg_config... yes 

啊啊啊啊啊

一旦在MacOS X 10.11上安装了当前的PostgreSQL应用程序,这就是pg_config文件是/Library/PostgreSQL/9.5/bin/pg_config

然后在docker:

  $ export PG_HOME=/Library/PostgreSQL/9.5 $ export PATH=$PATH:$PG_HOME/bin 

这将把path放在你正在使用的任何terminal的.profile中。

在你的环境中(假设你使用的是virtualenv )然后安装psycopg2:

  $ pip install psycopg2 

你应该看看你是否曾经下载过它:

  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 

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

一些可能性:

 /usr/local/bin/ /Library/PostgreSQL/9.2/bin/ /Applications/Postgres93.app/Contents/MacOS/bin/ /Applications/Postgres.app/Contents/Versions/9.3/bin/ 

难怪人们会感到困惑!

另外,如果您的$ PATH环境variables包含一个包含可执行文件的目录的path(要确认这一点,请在命令行中使用echo $PATH ),那么您可以运行which pg_configwhich psql等来找出哪里文件位于 。

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

brew安装postgresql

您可以使用其名称findpg_config目录:

 $ pg_config --bindir /usr/lib/postgresql/9.1/bin $ 

在Mac和Debian上testing。 唯一的问题是我看不到如何find安装在同一台机器上的不同版本的postgres的bindir。 虽然猜测相当简单! 🙂

注意:我使用以下命令将我的pg_config更新为Debian 9.5:

 sudo apt-get install postgresql-server-dev-9.5 

检查/Library/PostgreSQL/9.3/bin,你应该findpg_config

IE /Library/PostgreSQL/<version_num>/

ps:如果您认为您的pg需求是必要的,您可以执行以下操作 –

在〜目录下创build一个.profile

 export PG_HOME=/Library/PostgreSQL/9.3 export PATH=$PATH:$PG_HOME/bin 

现在,您可以使用terminal上的psqlpostgres命令,安装psycopg2或任何其他依赖项,而且您可以随时在ls $PG_HOME/bin

我用了 :

 export PATH=$PATH:/Library/PostgreSQL/9.6/bin pip install psycopg2 

在mac上有相同的问题,你可能需要

brew安装postgresql

那么你可以运行

pip安装psycopg2

brew将为您解决PATH问题

这个解决scheme至less适用于我。