uruu-github / uruu-blogapp2

0 stars 0 forks source link

pqをbundle installできない!! #23

Open uruu-github opened 1 month ago

uruu-github commented 1 month ago

gem 'pg', '>= 0.18', '< 2.0' 上記をGemfileに記述していますが、下記エラーが出ています。解決方法と原因はなにですか。 bundle install Fetching gem metadata from https://rubygems.org/......... Resolving dependencies... Using rake 13.2.1 Using base64 0.2.0 Using bigdecimal 3.1.8 Using concurrent-ruby 1.3.4 Using erubi 1.13.0 Using drb 2.2.1 Using logger 1.6.0 Using useragent 0.16.10 Using nio4r 2.7.3 Using websocket-extensions 0.1.5 Using zeitwerk 2.6.17 Using timeout 0.4.1 Using marcel 1.0.4 Using mini_mime 1.1.5 Using date 3.3.4 Using public_suffix 6.0.1 Using ast 2.4.2 Using aws-eventstream 1.3.0 Using aws-partitions 1.976.0 Using rack 3.1.7 Using minitest 5.25.1 Using rouge 4.3.0 Using bindex 0.8.1 Using debug_inspector 1.2.0 Using msgpack 1.7.2 Using bundler 2.3.27 Using byebug 11.1.3 Using matrix 0.4.2 Using regexp_parser 2.9.2 Using coderay 1.1.3 Using stringio 3.1.1 Using io-console 0.7.2 Using orm_adapter 0.5.0 Using webrick 1.8.1 Using thor 1.3.1 Using dotenv 3.1.2 Using erubis 2.7.0 Using temple 0.10.3 Using tilt 2.4.0 Using sexp_processor 4.17.2 Using error_highlight 0.6.0 Using ffi 1.17.0 (x86_64-darwin) Using json 2.7.2 Using language_server-protocol 3.17.0.3 Using method_source 1.1.0 Using parallel 1.26.3 Using bcrypt 3.1.20 Using securerandom 0.3.1 Using strscan 3.1.0 Using ruby-progressbar 1.13.0 Using unicode-display_width 2.5.0 Using builder 3.3.0 Using websocket 1.2.11 Using i18n 1.14.5 Using tzinfo 2.0.6 Using websocket-driver 0.7.6 Using net-protocol 0.2.2 Using addressable 2.8.7 Using aws-sigv4 1.9.1 Using puma 6.4.2 Using rack-session 2.0.0 Using rack-test 2.1.0 Using connection_pool 2.4.1 Using binding_of_caller 1.0.1 Using bootsnap 1.18.4 Using psych 5.1.2 Using reline 0.5.9 Using rackup 2.1.0 Using warden 1.2.9 Using haml 6.3.0 Using hamlit 3.0.3 Using pry 0.14.2 Using sassc 2.4.0 Using sprockets 4.2.1 Using net-imap 0.4.14 Using net-pop 0.1.2 Using net-smtp 0.5.0 Using better_errors 2.10.1 Using racc 1.8.1 Using faker 3.4.2 Using rexml 3.3.6 Using activesupport 7.2.1 Using rdoc 6.7.0 Using pry-byebug 3.10.1 Using redis-client 0.22.2 Using mail 2.8.1 Using crass 1.0.6 Using jmespath 1.6.2 Using rainbow 3.1.1 Using rubyzip 2.3.2 Using nokogiri 1.16.7 (x86_64-darwin) Using globalid 1.2.1 Using activemodel 7.2.1 Using aws-sdk-core 3.205.0 Using brakeman 6.2.1 Using irb 1.14.0 Using ruby_parser 3.21.1 Using parser 3.3.4.2 Using redis 5.3.0 Using rails-dom-testing 2.2.0 Using loofah 2.22.0 Using activejob 7.2.1 Using activerecord 7.2.1 Using aws-sdk-kms 1.91.0 Using xpath 3.2.0 Using debug 1.9.2 Using html2haml 2.3.0 Using rubocop-ast 1.32.1 Using selenium-webdriver 4.23.0 Using annotate 3.2.0 Using aws-sdk-s3 1.162.0 Using capybara 3.40.0 Using erb2haml 0.1.5 Using rubocop 1.65.1 Using rails-html-sanitizer 1.6.0 Using actionview 7.2.1 Using actionpack 7.2.1 Using jbuilder 2.12.0 Using sprockets-rails 3.5.2 Using actioncable 7.2.1 Using activestorage 7.2.1 Using actionmailer 7.2.1 Using railties 7.2.1 Using actionmailbox 7.2.1 Using responders 3.1.1 Using dotenv-rails 3.1.2 Using web-console 4.2.1 Using sassc-rails 2.1.2 Using stimulus-rails 1.3.4 Using actiontext 7.2.1 Using turbo-rails 2.0.6 Using importmap-rails 2.0.1 Using devise 4.9.4 Using rails 7.2.1 Installing pg 1.5.8 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/pg-1.5.8/ext

/Users/ayumu/.rbenv/versions/3.1.6/bin/ruby extconf.rb Calling libpq with GVL unlocked checking for pg_config... yes Using config values from /opt/homebrew/bin/pg_config checking for whether -Wl,-rpath,/opt/homebrew/opt/libpq/lib is accepted as LDFLAGS... yes Using libpq from /opt/homebrew/opt/libpq/lib 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)


Unable to find PostgreSQL client library.

Please install libpq or postgresql client package like so: brew install libpq

or try again with: gem install pg -- --with-pg-config=/path/to/pg_config

or set library paths manually with: gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/

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/ayumu/.rbenv/versions/3.1.6/bin/$(RUBY_BASE_NAME) --with-pg --without-pg --enable-gvl-unlock --disable-gvl-unlock --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 --with-pq-dir --without-pq-dir --with-pq-include --without-pq-include=${pq-dir}/include --with-pq-lib --without-pq-lib=${pq-dir}/lib --with-pqlib --without-pqlib --with-libpq-dir --without-libpq-dir --with-libpq-include --without-libpq-include=${libpq-dir}/include --with-libpq-lib --without-libpq-lib=${libpq-dir}/lib --with-libpqlib --without-libpqlib --with-ms/libpq-dir --without-ms/libpq-dir --with-ms/libpq-include --without-ms/libpq-include=${ms/libpq-dir}/include --with-ms/libpq-lib --without-ms/libpq-lib=${ms/libpq-dir}/lib --with-ms/libpqlib --without-ms/libpqlib

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

/Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/extensions/x86_64-darwin-23/3.1.0/pg-1.5.8/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/pg-1.5.8 for inspection. Results logged to /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/extensions/x86_64-darwin-23/3.1.0/pg-1.5.8/gem_make.out

/Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:125:in run' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/site_ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:28:in build' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:193:in build_extension' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:227:in block in build_extensions' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:224:in each' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:224:in build_extensions' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/site_ruby/3.1.0/rubygems/installer.rb:853:in build_extensions' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/rubygems_gem_installer.rb:72:in build_extensions' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/rubygems_gem_installer.rb:28:in install' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/source/rubygems.rb:207:in install' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/installer/gem_installer.rb:54:in install' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/installer/gem_installer.rb:16:in install_from_spec' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/installer/parallel_installer.rb:186:in do_install' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/installer/parallel_installer.rb:177:in block in worker_pool' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/worker.rb:62:in apply_func' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/worker.rb:57:in block in process_queue' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/worker.rb:54:in loop' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/worker.rb:54:in process_queue' /Users/ayumu/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/bundler-2.3.27/lib/bundler/worker.rb:91:in block (2 levels) in create_threads'

An error occurred while installing pg (1.5.8), and Bundler cannot continue.

In Gemfile: pg

uruu-github commented 1 month ago

ChatGPT回答

このエラーは、pg gemをインストールする際に、PostgreSQLのクライアントライブラリ(libpq)が見つからないために発生しています。pg gemはPostgreSQLのクライアントライブラリに依存しているため、このライブラリがシステムに適切にインストールされていない場合、ビルドが失敗します。

原因: エラーメッセージにある「Can't find the PostgreSQL client library (libpq)」は、PostgreSQLのクライアントライブラリが見つからないことを示しています。pg gemをビルドする際に、このライブラリが必要です。 macOSの場合、PostgreSQLは通常Homebrewを使ってインストールされますが、インストール後に環境変数の設定が必要な場合があります。 解決方法: PostgreSQLのクライアントライブラリをインストール:

brew install libpq libpqへのパスを通す: libpqは通常デフォルトのライブラリパスにインストールされないため、pg_configへのパスを手動で設定する必要があります。以下のコマンドを実行し、libpqを使えるようにします。

brew link --force libpq 再度pg gemをインストール: もし上記のコマンドで解決しない場合、以下のように、pg_configのパスを指定してpg gemをインストールします。

gem install pg -- --with-pg-config=/opt/homebrew/bin/pg_config これで、pg gemが正しくインストールされるはずです。再度bundle installを実行してみてください。

uruu-github commented 1 month ago

この流れでできた!!!!

arch -x86_64 /usr/local/bin/brew install libpq

Warning: libpq 16.4 is already installed and up-to-date. To reinstall 16.4, run: brew reinstall libpq gem install pg -- --with-pg-config=/usr/local/opt/libpq/bin/pg_config

Building native extensions with: '--with-pg-config=/usr/local/opt/libpq/bin/pg_config' This could take a while... Successfully installed pg-1.5.8 1 gem installed echo $PKG_CONFIG_PATH

/opt/homebrew/opt/libpq/lib/pkgconfig export PKG_CONFIG_PATH=/usr/local/opt/libpq/lib/pkgconfig

gem install pg -- --with-pg-config=/usr/local/opt/libpq/bin/pg_config

Building native extensions with: '--with-pg-config=/usr/local/opt/libpq/bin/pg_config' This could take a while... Successfully installed pg-1.5.8 1 gem installed echo $PKG_CONFIG_PATH

/usr/local/opt/libpq/lib/pkgconfig ruby -v gem list pg

ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-darwin23]

LOCAL GEMS

pg (1.5.8) bundle install

Fetching gem metadata from https://rubygems.org/......... Resolving dependencies... Using rake 13.2.1 Using base64 0.2.0 Using bigdecimal 3.1.8 Using concurrent-ruby 1.3.4 Using connection_pool 2.4.1 Using drb 2.2.1 Using rack 3.1.7 Using useragent 0.16.10 Using nio4r 2.7.3 Using websocket-extensions 0.1.5 Using zeitwerk 2.6.17 Using timeout 0.4.1 Using marcel 1.0.4 Using mini_mime 1.1.5 Using date 3.3.4 Using public_suffix 6.0.1 Using ast 2.4.2 Using aws-eventstream 1.3.0 Using aws-partitions 1.976.0 Using jmespath 1.6.2 Using bcrypt 3.1.20 Using rouge 4.3.0 Using bindex 0.8.1 Using debug_inspector 1.2.0 Using msgpack 1.7.2 Using bundler 2.3.27 Using byebug 11.1.3 Using matrix 0.4.2 Using regexp_parser 2.9.2 Using coderay 1.1.3 Using stringio 3.1.1 Using io-console 0.7.2 Using orm_adapter 0.5.0 Using webrick 1.8.1 Using thor 1.3.1 Using dotenv 3.1.2 Using erubis 2.7.0 Using temple 0.10.3 Using tilt 2.4.0 Using sexp_processor 4.17.2 Using error_highlight 0.6.0 Using ffi 1.17.0 (x86_64-darwin) Using json 2.7.2 Using language_server-protocol 3.17.0.3 Using method_source 1.1.0 Using parallel 1.26.3 Using pg 1.5.8 Using rainbow 3.1.1 Using strscan 3.1.0 Using ruby-progressbar 1.13.0 Using unicode-display_width 2.5.0 Using rubyzip 2.3.2 Using websocket 1.2.11 Using i18n 1.14.5 Using tzinfo 2.0.6 Using crass 1.0.6 Using logger 1.6.0 Using rack-test 2.1.0 Using websocket-driver 0.7.6 Using net-protocol 0.2.2 Using addressable 2.8.7 Using minitest 5.25.1 Using securerandom 0.3.1 Using builder 3.3.0 Using erubi 1.13.0 Using racc 1.8.1 Using rackup 2.1.0 Using binding_of_caller 1.0.1 Using haml 6.3.0 Using faker 3.4.2 Using hamlit 3.0.3 Using pry 0.14.2 Using puma 6.4.2 Using redis-client 0.22.2 Using rexml 3.3.6 Using sassc 2.4.0 Using sprockets 4.2.1 Using net-imap 0.4.14 Using net-pop 0.1.2 Using net-smtp 0.5.0 Using activesupport 7.2.1 Using better_errors 2.10.1 Using rack-session 2.0.0 Using warden 1.2.9 Using aws-sigv4 1.9.1 Using bootsnap 1.18.4 Using nokogiri 1.16.7 (x86_64-darwin) Using globalid 1.2.1 Using activemodel 7.2.1 Using mail 2.8.1 Using aws-sdk-core 3.205.0 Using brakeman 6.2.1 Using ruby_parser 3.21.1 Using parser 3.3.4.2 Using pry-byebug 3.10.1 Using redis 5.3.0 Using selenium-webdriver 4.23.0 Using psych 5.1.2 Using reline 0.5.9 Using loofah 2.22.0 Using activejob 7.2.1 Using activerecord 7.2.1 Using aws-sdk-kms 1.91.0 Using xpath 3.2.0 Using rdoc 6.7.0 Using html2haml 2.3.0 Using rubocop-ast 1.32.1 Using rails-dom-testing 2.2.0 Using rails-html-sanitizer 1.6.0 Using annotate 3.2.0 Using aws-sdk-s3 1.162.0 Using capybara 3.40.0 Using irb 1.14.0 Using erb2haml 0.1.5 Using rubocop 1.65.1 Using actionview 7.2.1 Using debug 1.9.2 Using actionpack 7.2.1 Using jbuilder 2.12.0 Using actioncable 7.2.1 Using activestorage 7.2.1 Using actionmailer 7.2.1 Using railties 7.2.1 Using sprockets-rails 3.5.2 Using actionmailbox 7.2.1 Using actiontext 7.2.1 Using responders 3.1.1 Using dotenv-rails 3.1.2 Using importmap-rails 2.0.1 Using sassc-rails 2.1.2 Using stimulus-rails 1.3.4 Using turbo-rails 2.0.6 Using web-console 4.2.1 Using devise 4.9.4 Using rails 7.2.1 Bundle complete! 29 Gemfile dependencies, 135 gems now installed. Use bundle info [gemname] to see where a bundled gem is installed.