Adding "gem 'pg'" to Gemfile causes "bundle install" to fail...

sampablokuper avatarsampablokuper created an issue

... as follows:

Installing pg (0.13.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.2-p290/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=/Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.2-p290/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
	--without-pg-config
	--with-pg_config
	--without-pg_config


Gem files will remain installed in /Volumes/Data/spikes/rails_in_top_directory/vendor/ruby/1.9.1/gems/pg-0.13.2 for inspection.
Results logged to /Volumes/Data/spikes/rails_in_top_directory/vendor/ruby/1.9.1/gems/pg-0.13.2/ext/gem_make.out
An error occured while installing pg (0.13.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.

This is on OS X 10.6.8 Snow Leopard, with the MacPorts postgresql91 port installed.

On the same system, with the MacPorts postgresql91 port and its dependencies uninstalled, and the latest EnterpriseDB package (9.1.3) installed instead, I get:

Installing pg (0.13.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.2-p290/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=/Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.2-p290/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
	--without-pg-config
	--with-pg_config
	--without-pg_config


Gem files will remain installed in /Volumes/Data/spikes/rails_in_top_directory/vendor/ruby/1.9.1/gems/pg-0.13.2 for inspection.
Results logged to /Volumes/Data/spikes/rails_in_top_directory/vendor/ruby/1.9.1/gems/pg-0.13.2/ext/gem_make.out
An error occured while installing pg (0.13.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.

I see that the pg instructions at http://deveiate.org/code/pg/README-OS_X_rdoc.html explain how to install pg using gem, but they do not explain how to install pg using bundler, which is an increasingly common approach.

If pg is designed to be installable simply by adding it to a Gemfile and bundling, then please read this bug report as a report that this is failing on OS X 10.6.8.

Alternatively, if pg is not yet designed to be installed in this way, then please read this bug report as a report that to meet user expectations, pg should be modified to become installable in this way.

Many thanks.

Comments (4)

  1. Michael Granger

    I don't use Bundler, but I'm not aware of any special hand-holding that it needs to install pg. As far as I know it's just a wrapper around Rubygems like Isolate.

    It appears from the installation output that you just don't have pg_config in your PATH. The relevant output from your pastes above is:

    No pg_config... trying anyway. If building fails, please try again with
     --with-pg-config=/path/to/pg_config
    

    Also, as Bundler says:

    Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.
    

    Did that work? If it gives you the same output, I'd suggest running gem install again with --with-pg-config set to the path to the relevant binary, or adding your PostgreSQL installation's bin/ directory to it, like so:

    # for the EnterpriseDB package
    export PATH=/Library/PostgreSQL/9.1/bin:$PATH
    
    # ...or, for Macports, approximately:
    export PATH=/opt/local/lib/postgresql91/bin:$PATH
    

    How to make Bundle pass that when installing pg is something that the Bundler people can probably answer.

  2. sampablokuper

    Sorry, didn't see your reply before posting the link to the MacPorts ticket.

    Running

    $ export PATH=/opt/local/lib/postgresql91/bin:${PATH}
    

    before calling Bundler allowed the installation to progress smoothly. Whose responsibility it should be to tell the pg installation process how to find pg_config, I don't know, but I don't think it should be the user's.

    I can think of two approaches you might want to consider, as the pg maintainer; you may be able to think of more:

    1. Co-ordinate with MacPorts folks (and/or other PostgreSQL packagers) to get them to add the directory containing pg_config to the $PATH upon installation of PostgreSQL; or
    2. Make the pg installation process more likely to succeed if PostgreSQL is installed but pg_config is not on the $PATH, e.g. by providing an interactive prompt (e.g. "If you haven't installed PostgreSQL, please do so before attempting to install the pg gem. Alternatively, if PostgreSQL is already installed, please enter the path to pg_config:").

    Thanks again.

  3. Michael Granger

    If it's not the user's responsibility, then I don't know who that leaves. The user is the person most-qualified to inform the installation process, as she is the only person that knows what particular combination of OS, Ruby interpreter, directory structure, third party dependencies, and PostgreSQL installation is in effect.

    As for your first suggestion: I don't have time (or, frankly, the motivation) to track down every package maintainer that installs PostgreSQL and get them to add the directory with the command-line tools to the user's PATH. If they don't, I assume they probably have a reason.

    Prompting the user seems like a good idea, but installation is just as likely to be in the middle of a non-interactive session, which would block indefinitely waiting for the answer that will never come. I could check for a tty, but I don't know how portable that is.

    I've tried to make the error output give as many hints as possible, but people by and large don't seem to read error output beyond a few lines. Even when the exact advice needed to install is in the output. I have a ticket open (#89) to improve the diagnostics for failed installation, but I can't see how to make your particular situation any more clear given what gem install will let you output.

  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.