0

我在 Mac OS X 10.8.2 上,几个小时前我重新安装了它,对随后的问题感到沮丧。

我已经安装了 Homebrew,当我运行时brew doctor,它说Your system is raring to brew.

我有带有命令行实用程序的最新 Xcode。

我已经使用 Homebrew 安装了 PostgreSQL。

steven$ ls /usr/local/Cellar/postgresql/9.2.1
COPYRIGHT           README              homebrew.mxcl.postgresql.plist  lib
INSTALL_RECEIPT.json        bin             include             share

steven$ psql --version
psql (PostgreSQL) 9.2.1
iMac-001EC20A3C44-5:9.2.1 steven$ which psql
/usr/local/bin/psql

我的 Gemfile 中有一个 Rail 应用程序gem 'pg',但我无法安装 gem:

steven$ bundle install
Fetching source index for http://rubygems.org/
Installing pg (0.14.1) with native extensions /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/installer.rb:482:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-pg-config=/usr/pgsql-9.1/bin/pg_config
Using config values from /usr/pgsql-9.1/bin/pg_config
sh: /usr/pgsql-9.1/bin/pg_config: No such file or directory
sh: /usr/pgsql-9.1/bin/pg_config: No such file or directory
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

它似乎在寻找 pg_config 和 libpq,它们很容易找到:

steven$ ls /usr/local/Cellar/postgresql/9.2.1/bin
...     pg_config       ...
steven$ ls /usr/local/Cellar/postgresql/9.2.1/include
...     libpq           ...

所以我尝试通过我能想到的每个配置选项,但没有一个工作:

steven$ sudo gem install pg -- --with-pg-config="/usr/local/Cellar/postgresql/9.2.1/bin"
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin
Using config values from /usr/local/Cellar/postgresql/9.2.1/bin
sh: /usr/local/Cellar/postgresql/9.2.1/bin: is a directory
sh: /usr/local/Cellar/postgresql/9.2.1/bin: is a directory
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib

steven$ sudo gem install pg -- --with-pg-config="/usr/local/Cellar/postgresql/9.2.1/bin" --with-libpqlib="/usr/local/Cellar/postgresql/9.2.1/include"
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin --with-libpqlib=/usr/local/Cellar/postgresql/9.2.1/include
Using config values from /usr/local/Cellar/postgresql/9.2.1/bin
sh: /usr/local/Cellar/postgresql/9.2.1/bin: is a directory
sh: /usr/local/Cellar/postgresql/9.2.1/bin: is a directory
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -l/usr/local/Cellar/postgresql/9.2.1/include... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib

steven$ sudo gem install pg --with-pg-config="/usr/local/Cellar/postgresql/9.2.1/bin" --with-libpqlib="/usr/local/Cellar/postgresql/9.2.1/include"
ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin

steven$ sudo gem install pg --with-pg-config="/usr/local/Cellar/postgresql/9.2.1/bin/" --with-libpqlib="/usr/local/Cellar/postgresql/9.2.1/include/"
ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin/

steven$ sudo gem install pg --with-pg-config='/usr/local/Cellar/postgresql/9.2.1/bin/' --with-libpqlib='/usr/local/Cellar/postgresql/9.2.1/include/'
ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin/

steven$ sudo gem install pg -- --with-pg-config='/usr/local/Cellar/postgresql/9.2.1/bin/' --with-libpqlib='/usr/local/Cellar/postgresql/9.2.1/include/'
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin/ --with-libpqlib=/usr/local/Cellar/postgresql/9.2.1/include/
Using config values from /usr/local/Cellar/postgresql/9.2.1/bin/
sh: /usr/local/Cellar/postgresql/9.2.1/bin/: is a directory
sh: /usr/local/Cellar/postgresql/9.2.1/bin/: is a directory
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -l/usr/local/Cellar/postgresql/9.2.1/include/... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib

steven$ sudo gem install pg --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin/ --with-libpqlib=/usr/local/Cellar/postgresql/9.2.1/include
ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin/
iMac-001EC20A3C44-5:testivate steven$ sudo gem install pg --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin/pg_config

ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --with-pg-config=/usr/local/Cellar/postgresql/9.2.1/bin/pg_config

我应该怎么办?

4

2 回答 2

2

仅供参考,我最终通过卸载从 PostgreSQL 和 pg gem 到 Bundler、Homebrew 甚至 RVM 的所有内容来解决这个问题,然后一次又一次地安装每一件。可能我删除的内容超出了我必须删除的内容,但是一旦我将它们重新组合在一起,一切都会正常进行。

于 2012-10-03T20:23:10.067 回答
1

我不知道这是否对其他人有帮助,但我在这里遇到了完全相同的问题,PG gem 没有编译。我的应用程序在 Heroku 上,在本地我使用 RVM、Homebrew,但对于 Postgres,我使用的是Postgresapp.com

我还使用JewerlyBox为我提供了一个围绕 RVM 的漂亮 GUI 包装器。我将我的 Ruby 1.9.3-p194 与 1.9.3-p286 进行了比较,发现我已将 286 设置为通用。我对卸载所有东西犹豫不决,所以我只是卸载了 Ruby 并重新安装了仅设置为 64 位的选项(平台:“x86_64-darwin12.2.0”)。

使用此选项重新安装 Ruby 后,PG gem 安装顺利,我又恢复了快乐。希望这可以帮助某人。

在此处输入图像描述

于 2012-10-20T04:10:17.450 回答