【问题标题】:How to find pg_config path如何找到 pg_config 路径
【发布时间】:2014-01-31 12:31:30
【问题描述】:

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

我使用的是 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'.

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

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

【问题讨论】:

  • 在终端尝试sudo find / -name pg_config
  • 作为 Mac OS X 用户,请务必说明您如何安装 PostgreSQL。用于 OS X 的 PostgreSQL 包有太多不同的包,它们都有自己奇怪和令人沮丧的怪癖。自制?麦克波特? Postgres.app?从源头?教育局? ...

标签: python django macos postgresql


【解决方案1】:

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

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

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

【讨论】:

  • 现在在/Applications/Postgres.app/Contents/Versions/9.3/bin
  • 在 9.4 中它在这里:/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
  • 这是否意味着每次更新我都必须记住更改版本?现在是 9.5
  • export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH" 应该适用于任何最新版本。
  • 或者简单地说,为了避免版本号:/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
【解决方案2】:
sudo find / -name "pg_config" -print

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

【讨论】:

    【解决方案3】:

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

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

    其中 9.4 – PostgreSQL 版本。

    【讨论】:

    • 不知道为什么这被否决了,但这是正确的——至少对于 9.3 及更高版本...
    【解决方案4】:

    安装自制软件

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

    然后安装postgresql

    brew install postgresql
    

    给了我这个可爱的输出:

    checking for pg_config... yes
    

    啊啊啊啊啊啊

    【讨论】:

      【解决方案5】:

      在 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
      

      这会将路径放在您正在使用的任何终端的 .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
      

      【讨论】:

      • 太棒了。就我而言,它不在文件夹库下。它位于 /Applications/Postgres.app/.... 非常感谢!
      【解决方案6】:

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

      一些可能性:

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

      难怪人们会感到困惑!

      此外,如果您的 $PATH 环境变量包含指向包含可执行文件的目录的路径(要确认这一点,请在命令行上使用 echo $PATH),那么您可以运行 which pg_configwhich psql 等。找出where the file is located

      【讨论】:

        【解决方案7】:

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

        brew 安装 postgresql

        【讨论】:

          【解决方案8】:

          在mac上遇到同样的问题,你可能需要

          brew 安装 postgresql

          然后你就可以运行了

          pip 安装 psycopg2

          brew 将为您解决 PATH 问题

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

          【讨论】:

          • 适用于我在 MacOS Catalina 版本 10.15.5 中。
          • 在尝试了上述所有选项后,在 MacOs Mojave 中同样适用于我
          【解决方案9】:

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

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

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

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

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

          【讨论】:

          • 你还没有理解问题所在。 OP 收到错误是因为pg_config 不在PATH 中列出的目录中。鉴于这种情况,然后像您展示的那样在 shell 上运行 pg_config 将无法工作出于完全相同的原因
          • 正确 - 抱歉。我在寻找路径时发现了这个并且略读了太多!
          • 这里唯一帮助我获得 0 票的答案...我只能提供一张。如果它对任何人有帮助,请在/usr/local/Cellar/postgresql/9.5.2/bin 安装 brew(版本 9.5.2)
          【解决方案10】:

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

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

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

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

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

          您现在可以从终端使用 psqlpostgres 命令,并安装 psycopg2 或任何其他依赖项而不会出现问题,此外,当您想偷看您的 pg_dir 时,您始终可以只使用 ls $PG_HOME/bin

          【讨论】:

            【解决方案11】:

            我用过:

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

            【讨论】:

              【解决方案12】:

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

              $ which pg_config                 // prints the directory location 
              /usr/bin/pg_config
              

              【讨论】:

                【解决方案13】:

                通过首先安装以下 pip 包为我工作:libpq-devpostgresql-common

                【讨论】:

                • ..question 是关于找到一个文件夹...您正在为安装软件包增添乐趣...
                【解决方案14】:

                在我的例子中 pg_config 的路径(MacOS)

                /Library/PostgreSQL/13/bin

                在终端执行以下操作:

                PATH="/Library/PostgreSQL/13/bin:$PATH"
                

                然后

                pip install psycopg2
                

                【讨论】:

                  【解决方案15】:

                  对于寻找通过 brewApple Silicon 上安装的 postgresql 的 pg_config 路径的人:/opt/homebrew/Cellar/postgresql/<postgres_version>/bin

                  适用于基于 Intel 的 Mac 系统 /usr/local/Cellar/postgresql/<postgres_version>/bin(需要验证)。

                  【讨论】:

                    【解决方案16】:

                    对于那些使用 macOS Big Sur 并将其默认 shell 作为 Z shell 的用户,您可以在 .zprofile 中添加 py_config 二进制文件的路径,该路径等同于 .bash_profile,如此链接中所述https://support.apple.com/en-us/HT208050

                    在将 PyCharm 与虚拟环境一起使用时,我遇到了类似的问题,在该虚拟环境中,我无法将 shell 更改为 bash 以使事情顺利进行。添加 postgres bin 路径解决了我的问题:

                    MacBook-Pro ~ % cat .zprofile
                    # Setting PATH for Postgres
                    PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
                    export PATH
                    

                    然后运行它没有任何问题:

                    pip install psycopg2
                    

                    【讨论】:

                      猜你喜欢
                      • 1970-01-01
                      • 2020-01-11
                      • 2020-02-25
                      • 2023-03-11
                      • 2017-03-24
                      • 2017-06-24
                      • 1970-01-01
                      • 1970-01-01
                      相关资源
                      最近更新 更多