gem pg,'libpq-fe.h header' 和 Heroku 推送错误

gem pg, 'libpq-fe.h header' and Heroku push error

我按照教程创建了(通过 rails new)三个看似相同的 rails 应用程序。前两个可以通过 rails server 在本地或 heroku open 启动,没有任何问题。第三个——也是通过 rails new 生成的——可以在本地启动(通过 rails server),但不能通过 heroku open 启动。经过大量阅读,我得出结论,它与 gem 'pg' 有关,但为什么这不是其他两个应用程序的问题?我什至从一个 "successful" 应用程序复制了 Gemfile,看看我是否可以让第三个应用程序在 Heroku 上运行(不行)。非常感谢任何见解!

所以这是 bundle install 结果:

Using rake 12.3.1
Using concurrent-ruby 1.0.5
Using i18n 1.1.0
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.1
Using builder 3.2.3
Using erubi 1.7.1
Using mini_portile2 2.3.0
Using nokogiri 1.8.4
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.2
Using rails-html-sanitizer 1.0.4
Using actionview 5.2.1
Using rack 2.0.5
Using rack-test 1.1.0
Using actionpack 5.2.1
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using websocket-driver 0.7.0
Using actioncable 5.2.1
Using globalid 0.4.1
Using activejob 5.2.1
Using mini_mime 1.0.0
Using mail 2.7.0
Using actionmailer 5.2.1
Using activemodel 5.2.1
Using arel 9.0.0
Using activerecord 5.2.1
Using mimemagic 0.3.2
Using marcel 0.3.2
Using activestorage 5.2.1
Using public_suffix 3.0.2
Using addressable 2.5.2
Using io-like 0.3.0
Using archive-zip 0.11.0
Using execjs 2.7.0
Using autoprefixer-rails 9.1.0
Using coderay 1.1.2
Using better_errors 2.4.0
Using bindex 0.5.0
Using msgpack 1.2.4
Using bootsnap 1.3.1
Using rb-fsevent 0.10.3
Using ffi 1.9.25
Using rb-inotify 0.9.10
Using sass-listen 4.0.0
Using sass 3.5.7
Using bootstrap-sass 3.3.7
Using bundler 1.16.3
Using byebug 10.0.2
Using xpath 3.1.0
Using capybara 3.5.1
Using childprocess 0.9.0
Using chromedriver-helper 1.2.0
Using coffee-script-source 1.12.2
Using coffee-script 2.4.1
Using method_source 0.9.0
Using thor 0.20.0
Using railties 5.2.1
Using coffee-rails 4.2.2
Using multipart-post 2.0.0
Using faraday 0.15.2
Using multi_json 1.13.1
Using gibbon 3.2.0
Using high_voltage 3.1.0
Using jbuilder 2.7.0
Using jquery-rails 4.3.3
Using ruby_dep 1.5.0
Using listen 3.1.5
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.2.1
Using minitest-spec-rails 5.4.0
Fetching pg 0.20.0
Installing pg 0.20.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/new-laptop/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/pg-0.20.0/ext
/Users/new-laptop/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20180808-7108-inkyrf.rb 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/new-laptop/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --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

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/new-laptop/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/pg-0.20.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/new-laptop/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/pg-0.20.0 for inspection.
Results logged to /Users/new-laptop/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/pg-0.20.0/gem_make.out

An error occurred while installing pg (0.20.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.20.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  pg

这是 mkmf.log 日志:

New-Laptop:toy_app new-laptop$ cat  /Users/new-laptop/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/pg-0.20.0/mkmf.log
find_executable: checking for pg_config... -------------------- no

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

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

"clang -o conftest -I/Users/new-laptop/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-darwin17 -I/Users/new-laptop/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/Users/new-laptop/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/Users/new-laptop/.rbenv/versions/2.5.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/new-laptop/.rbenv/versions/2.5.1/lib -L. -L/Users/new-laptop/.rbenv/versions/2.5.1/lib  -fstack-protector -L/usr/local/lib     -lruby.2.5.1-static -framework Foundation  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"clang -E -I/Users/new-laptop/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-darwin17 -I/Users/new-laptop/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/Users/new-laptop/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/Users/new-laptop/.rbenv/versions/2.5.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -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 */

您的计算机上似乎没有安装 PostgreSQL。首先安装 PostgreSQL(例如通过自制软件):

brew install postgresql

然后再次捆绑:

bundle install

如果您使用 Postgres.app 来 运行 您的数据库,请参阅 https://coderwall.com/p/279aqg/install-pg-gem-with-postgres-app

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/my-version/bin/pg_config