Вопрос

Just did a simple bundle update and got an annoying error related to the pg gem for PostgreSQL. I don't have PostgreSQL installed on my system (unless it's automatically installed for Mac OS X 10.9.1). This has never been an issue before. Any ideas?

Using jquery-rails (3.0.4) 
Using jquery-rails-cdn (1.0.1) 
Installing liquid (2.6.1) 
Using paperclip (3.5.2) 
Installing pg (0.17.1) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/scott/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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=/Users/scott/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib


Gem files will remain installed in /Users/scott/.rvm/gems/ruby-1.9.3-p194@ucode/gems/pg-0.17.1 for inspection.
Results logged to /Users/scott/.rvm/gems/ruby-1.9.3-p194@ucode/gems/pg-0.17.1/ext/gem_make.out

An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.


$ gem list pg

*** LOCAL GEMS ***

pg (0.17.0, 0.16.0, 0.15.1, 0.15.0, 0.14.1)

UPDATE: as requested, this is my mkmf.log file

find_executable: checking for pg_config... -------------------- no

--------------------

find_header: checking for libpq-fe.h... -------------------- no

"/usr/bin/gcc-4.2 -o conftest -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin12.2.0 -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/include -fno-common -pipe conftest.c  -L. -L/Users/scott/.rvm/rubies/ruby-1.9.3-p194/lib -L. -L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib     -lruby.1.9.1  -lpthread -ldl -lobjc "
ld: warning: directory not found for option '-L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

"/usr/bin/gcc-4.2 -E -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin12.2.0 -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/include -fno-common -pipe  conftest.c -o conftest.i"
conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
#include <libpq-fe.h>
         ^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
/* end */

--------------------

UPDATE 2: The only mention of pg in my Gemfile is here:

group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end
Это было полезно?

Решение

The easiest way is to install Postgres.app.

Then do:

$ gem install pg -v '0.17.1' && bundle update

Edit: Do not forget to add the relevant directories into your PATH.

Другие советы

try reinstall pg gem gem install pg --with-pg-config=/path/to/pg_config


I recomended install this app Postgres and install gem:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config

check this blog this guy have a details explanation of how to do this

http://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac.html

Newbie here. I had the same error after doing a git clean -xdf. For some reason after I did this I could not start my local rails server nor would bundle install / update work giving the same pg gem errors. It was basically ignoring the following in my gemfile:

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

I was able to fix things by running the following line again. I guess it's set this back to default as I can now also just use bundle install when making updates.

bundle install --without production
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top