ruby 无法在MacOSX上使用www.example.com安装带有本机扩展的pg 1.4.6Postgres.app

ibps3vxo  于 2023-04-20  发布在  Ruby
关注(0)|答案(1)|浏览(88)

我尝试运行rails s,但在本地机器上安装用于www.example.com的pg gem时遇到故障Postgres.app。我正在运行Ventura。
Postgres.app 已经安装并运行正常,但我无法让pg gem工作。我做了以下操作:

  • 根据文档安装了Postgres App
  • 使用Postgres.app文档中的命令'env ARCHFLAGS="-arch x86_64”gem install pg -- --with-pg-config=/Applications/Postgres.app_config'
  • Homebrew更新和升级
  • 安装了Xcode开发工具

更新了我的$PATH以引用Postgres.app存储在.zshrc文件中的www.example.com bin和lib目录

zshrc文件

eval "$(rbenv init - zsh)"

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"
  export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"

  export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"

export PKG_CONFIG_PATH="/opt/homebrew/opt/libpq/lib/pkgconfig"

问题是运行bundlebundle install时持续存在

$ bundle     
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies....
Using rake 13.0.6
Using concurrent-ruby 1.1.10
Using minitest 5.16.3
Using builder 3.2.4
Using racc 1.6.1
Using erubi 1.11.0
Using date 3.3.1
Using rack 2.2.4
Using ansi 1.5.0
Using websocket-extensions 0.1.5
Using msgpack 1.6.0
Using byebug 11.1.3
Using io-console 0.5.11
Using mini_mime 1.1.2
Using coderay 1.1.3
Using crass 1.0.6
Using timeout 0.3.1
Using diff-lcs 1.5.0
Using thor 1.2.1
Using rspec-support 3.12.0
Using marcel 1.0.2
Using i18n 1.12.0
Using method_source 1.0.0
Using ruby-progressbar 1.13.0
Using tzinfo 2.0.5
Using bundler 2.3.26
Using reline 0.3.1
Using nokogiri 1.13.10 (arm64-darwin)
Using net-protocol 0.2.1
Using rspec-core 3.12.1
Using rack-test 2.0.2
Using rspec-expectations 3.12.2
Using nio4r 2.5.8
Using zeitwerk 2.6.6
Using websocket-driver 0.7.5
Using rspec-mocks 3.12.4
Using pry 0.14.2
Using minitest-reporters 1.6.0
Using bootsnap 1.15.0
Using activesupport 7.0.4
Using irb 1.6.1
Using puma 5.6.5
Using loofah 2.19.1
Using globalid 1.0.0
Using activemodel 7.0.4
Using rspec 3.12.0
Using debug 1.7.0
Using rails-html-sanitizer 1.4.4
Using net-smtp 0.3.3
Using rails-dom-testing 2.0.3
Using net-imap 0.3.2
Using activejob 7.0.4
Using net-pop 0.1.2
Using activerecord 7.0.4
Using actionview 7.0.4
Using actionpack 7.0.4
Using mail 2.8.0
Using actioncable 7.0.4
Using actionmailer 7.0.4
Using activestorage 7.0.4
Using railties 7.0.4
Using actiontext 7.0.4
Using actionmailbox 7.0.4
Using rails 7.0.4
Installing pg 1.4.6 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/username/Documents/GitHub/projectFolder/.bundle/ruby/3.1.0/gems/pg-1.4.6/ext
/Users/username/.rbenv/versions/3.1.3/bin/ruby -I /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0 extconf.rb
**--with-pg-config\=/usr/pgsql-9.3/bin/pg_config**
Calling libpq with GVL unlocked
Using config values from /usr/pgsql-9.3/bin/pg_config
*** 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/username/.rbenv/versions/3.1.3/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --enable-gvl-unlock
    --disable-gvl-unlock
    --enable-windows-cross
    --disable-windows-cross
    --with-pg-config
extconf.rb:40:in `popen': No such file or directory - /usr/pgsql-9.3/bin/pg_config (Errno::ENOENT)
    from extconf.rb:40:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in
/Users/username/Documents/GitHub/projectFolder/.bundle/ruby/3.1.0/gems/pg-1.4.6 for inspection.
Results logged to
/Users/username/Documents/GitHub/projectFolder/.bundle/ruby/3.1.0/extensions/arm64-darwin-22/3.1.0/pg-1.4.6/gem_make.out

  /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:102:in `run'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:28:in `build'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:171:in `build_extension'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:205:in `block in build_extensions'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in `each'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in `build_extensions'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/3.1.0/rubygems/installer.rb:843:in `build_extensions'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/source/rubygems.rb:207:in `install'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:186:in `do_install'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:62:in `apply_func'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:54:in `loop'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:54:in `process_queue'
  /Users/username/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads'

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

In Gemfile:
  pg

我也注意到这一行:--with-pg-config=/usr/pgsql-9.3/bin/pg_configWhere is a concern because I am using Postgres App version(15 or 15.2 or latest)all according to the command below.
我希望当运行rails s命令时,我应该能够启动rails服务器。直到上周,我一直运行得很好。我通过hombrew下载postgres。由于我无法修复它,我通过hombrew卸载postgres并开始使用postgressApp。最终,$PATH配置工作,但pg安装一直失败。
运行以下命令时的结果:

$ psql

psql (15.2)

$ which pg_config

/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config\

$ echo $PATH

/opt/homebrew/opt/openssl@3/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/username/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Postgres.app/Contents/Versions/latest/bin

$ find /Applications -name pg_config

/Applications/Postgres.app/Contents/Versions/15/bin/pg_config

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

Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config'
This could take a while...
Successfully installed pg-1.4.6
1 gem installed

$ cd ~/.rbenv ; find . -name mkmf.log | grep pg`

./versions/3.1.3/lib/ruby/gems/3.1.0/extensions/arm64-darwin-22/3.1.0/pg-1.1.0/mkmf.log
./versions/3.1.3/lib/ruby/gems/3.1.0/extensions/arm64-darwin-22/3.1.0/pg-1.4.5/mkmf.log
./versions/3.1.3/lib/ruby/gems/3.1.0/extensions/arm64-darwin-22/3.1.0/pg-1.4.6/mkmf.log
./versions/2.7.4/lib/ruby/gems/2.7.0/extensions/arm64-darwin-22/2.7.0/pg-1.2.3/mkmf.log

所以很明显,pg已经成功安装,但不知道如何修复以下问题

由于某些原因,无法创建Makefile,可能是缺少必要的库和/或头文件。请查看mkmf.log文件了解详细信息。您可能需要配置选项。

vc6uscn9

vc6uscn91#

你说你在用这面旗:

env ARCHFLAGS="-arch x86_64"

但后来你说你有Homebrew安装在:

/opt/homebrew

这是Homebrew安装在Apple Silicon Mac上的位置。同样,您有路径:

./versions/3.1.3/lib/ruby/gems/3.1.0/extensions/arm64-darwin-22/

这表示arm64,而不是x86_64。
我的建议是删除Postgres.app,而不是install Postgres through Homebrew

brew install postgresql@15

然后删除用于编译gem的所有自定义标志,并使用默认值。

相关问题