Python 如何找到 pg_config 路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21079820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:00:36  来源:igfitidea点击:

How to find pg_config path

pythondjangomacospostgresql

提问by Ben

Complete newbie here, trying to set up Django to work with PostgreSQL.

在这里完全是新手,尝试设置 Django 以使用 PostgreSQL。

I'm using mac osx 10.6.8. I have also installed PostgreSQL 9.3

我使用的是 mac osx 10.6.8。我还安装了 PostgreSQL 9.3

When I run pip install psycopg2in terminal I get the following error

当我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'.

I've seen a number of posts on this
how-to-install-psycopg2-with-pip-on-python
pg-config-executable-not-found

我已经看过很多关于这个
how-to-install-psycopg2-with-pip-on-python pg-config-executable-not-found的帖子

but I have no clue how to find the bin folder location containing pg_config. Any tips on finding this path?

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

采纳答案by elynch

I recommend that you try to use Postgres.app. (http://postgresapp.com) This way you can easily turn Postgres on and off on your Mac. Once you do, add the path to Postgres to your .profilefile by appending the following:

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

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

Only after you added Postgres to your path you can try to install psycopg2either within a virtual environment (using pip) or into your global site packages.

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

回答by user1953296

sudo find / -name "pg_config" -print

The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)

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

回答by Daniil Ryzhkov

Postgres.app was updated recently. Now it stores all the binaries in "Versions" folder

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

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

Where 9.4 –?version of PostgreSQL.

其中 9.4 -?版本的 PostgreSQL。

回答by cpres

Installing homebrew

安装自制软件

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

And then installing postgresql

然后安装postgresql

brew install postgresql

gave me this lovely bit of output:

给了我这个可爱的输出:

checking for pg_config... yes

ahhh yeahhhhh

啊啊啊啊啊

回答by jkdev

To summarize -- PostgreSQL installs its files (including its binary or executable files) in different locations, depending on the version number and the installation method.

总而言之——PostgreSQL 将其文件(包括其二进制文件或可执行文件)安装在不同的位置,具体取决于版本号和安装方法。

Some of the possibilities:

一些可能性:

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

No wonder people get confused!

难怪人们会感到困惑!

Also, if your $PATH environment variable includes a path to the directory that includes an executable file (to confirm this, use echo $PATHon the command line) then you can run which pg_config, which psql, etc. to find out where the file is located.

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

回答by romainm

I had exactly the same error, but I installed postgreSQL through brew and re-run the original command and it worked perfectly :

我遇到了完全相同的错误,但是我通过 brew 安装了 postgreSQL 并重新运行了原始命令,它运行良好:

brew install postgresql

brew 安装 postgresql

回答by codesage

check /Library/PostgreSQL/9.3/bin and you should find pg_config

检查 /Library/PostgreSQL/9.3/bin 你应该找到 pg_config

I.E. /Library/PostgreSQL/<version_num>/

IE /Library/PostgreSQL/<version_num>/

ps: you can do the following if you deem it necessary for your pg needs -

ps:如果您认为有必要满足您的 pg 需求,您可以执行以下操作 -

create a .profile in your ~ directory

在您的 ~ 目录中创建一个 .profile

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

You can now use psqlor postgrescommands from the terminal, and install psycopg2 or any other dependency without issues, plus you can always just ls $PG_HOME/binwhen you feel like peeking at your pg_dir.

您现在可以从终端使用psqlpostgres命令,并毫无问题地安装 psycopg2 或任何其他依赖项,而且您可以随时ls $PG_HOME/bin查看 pg_dir。

回答by Afrowave

Once you install the current PostgreSQL app on the MacOS X 10.11, this is where the pg_config file is /Library/PostgreSQL/9.5/bin/pg_config.

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

Then on the Terminal:

然后在终端上:

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

This will put the path in the .profile of whatever terminal you are using.

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

In your environment (assuming you are using virtualenv) you then install psycopg2:

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

    $ pip install psycopg2

You should see if you had downloaded it before:

你应该看看你之前是否下载过它:

    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

回答by Max Murphy

You can find the pg_configdirectory using its namesake:

您可以pg_config使用其同名找到该目录:

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

Tested on Mac and Debian. The only wrinkle is that I can't see how to find the bindir for different versions of postgres installed on the same machine. It's fairly easy to guess though! :-)

在 Mac 和 Debian 上测试。唯一的问题是我看不到如何为安装在同一台机器上的不同版本的 postgres 找到 bindir。不过还是很容易猜的!:-)

Note: I updated my pg_config to 9.5 on Debian with:

注意:我在 Debian 上将我的 pg_config 更新为 9.5:

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

回答by Deepika Anand

I used :

我用了 :

export PATH=$PATH:/Library/PostgreSQL/9.6/bin

pip install psycopg2