gem pg,“ libpq-fe.h标头”和Heroku推送错误

时间:2018-08-09 03:39:08

标签: ruby-on-rails ruby heroku rubygems

我遵循了教程,并(通过rails new创建了三个看似相同的Rails应用程序。前两个可以通过rails server在本地或heroku open上启动而没有任何问题。第三个(也是通过rails new生成的)可以在本地启动(通过rails server),但不能与heroku open一起启动。经过大量阅读后,我得出结论认为它与gem'pg'有关,但是为什么这两个其他应用程序都不会有问题?我什至从一个“成功的”应用程序中复制了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 */

2 个答案:

答案 0 :(得分:2)

您的计算机上似乎未安装PostgreSQL。首先安装PostgreSQL(例如通过自制程序):

brew install postgresql

然后再次捆绑:

bundle install

答案 1 :(得分:0)

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

  

gem install pg---with-pg-config = / Applications / Postgres.app / Contents / Versions / 我的版本 / bin / pg_config