macos - pg gem 找不到 native 扩展——使用 Homebrew 安装的 PostgreSQL

标签 macos postgresql bundler homebrew

我在 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

我有一个 Rail 应用程序,其 Gemfile 中包含 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

我该怎么办?

最佳答案

仅供引用,我最终解决了这个问题,方法是卸载从 PostgreSQL 和 pg gem 到 Bundler、Homebrew 甚至 RVM 的所有内容,然后再一次一个地重新安装。可能我移除的东西比我必须移除的要多,但一旦我将它们重新组合在一起,一切都会起作用。

关于macos - pg gem 找不到 native 扩展——使用 Homebrew 安装的 PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12690677/

相关文章:

python - BSD/OS X 上的网络掩码/IP 地址查找

cocoa - Apple mail.app 的 API?不公开?

Python psycopg2 : Copy result of query to another table

date - 在 postgresql 8.3 中创建日期系列

macos - 无法从终端使用 git

sql - psql query CASE vs Multiple select for a large data-sets - performance

ruby-on-rails - 为什么 "install"运行两次?

ruby-on-rails - 在 gem 的 rake 任务中需要 gem

ruby-on-rails - 当 gemspec 声明开放约束时,为什么 bundler 坚持使用确切的 gem 版本号?

java - 使用较新版本的 Java,我的一些应用程序快捷方式被 MacOS 快捷方式覆盖