无法在 M1 处理器上使用 Nokogiri gem



我在使用M1处理器和Nokogiri gem时遇到问题。

Gemfile

...
gem 'nokogiri', '>= 1.13.5'
...

当我运行bundle install时,一切似乎都很好,但当我尝试运行规范时,例如,我看到错误:

LoadError:
dlopen(/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle, 0x0009): tried: '/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) - /Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle

我试着用gem install nokogiri -v 1.13.6 --platform arm64-darwin安装Nokogiri,现在看起来是这样的:

nokogiri-版本:

# Nokogiri (1.13.6)
---
warnings: []
nokogiri:
version: 1.13.6
cppflags:
- "-I/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri"
- "-I/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri/include"
- "-I/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri/include/libxml2"
ldflags: []
ruby:
version: 2.7.2
platform: arm64-darwin21
gem_platform: arm64-darwin-21
description: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin21]
engine: ruby
libxml:
source: packaged
precompiled: true
patches:
- 0001-Remove-script-macro-support.patch
- 0002-Update-entities-to-remove-handling-of-ssi.patch
- 0003-libxml2.la-is-in-top_builddir.patch
- 0004-use-glibc-strlen.patch
- 0005-avoid-isnan-isinf.patch
- 0006-update-automake-files-for-arm64.patch
- '0008-htmlParseComment-handle-abruptly-closed-comments.patch'
- '0009-allow-wildcard-namespaces.patch'
libxml2_path: "/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri"
memory_management: ruby
iconv_enabled: true
compiled: 2.9.14
loaded: 2.9.14
libxslt:
source: packaged
precompiled: true
patches:
- 0001-update-automake-files-for-arm64.patch
datetime_enabled: true
compiled: 1.1.35
loaded: 1.1.35
other_libraries:
zlib: 1.2.12
libiconv: '1.16'
libgumbo: 1.0.0-nokogiri

但当我试图只使用这个版本运行规范时,我出现了一个错误:

Could not find nokogiri-1.13.6 in any of the sources
Run `bundle install` to install missing gems.

因此,为了避免这个错误,我必须通过bundle install安装Nokogiri,但它安装了错误的版本,不适用于arm平台,然后我的平台出现了问题。如果我通过gem install命令安装Nokogiri,bundler看不到它

我的捆绑包配置

Settings are listed in order of priority. The top value will be used.
build.libv8
Set for the current user (/Users/ruslan/.bundle/config): "--with-system-v8"
build.libxml-ruby
Set for the current user (/Users/ruslan/.bundle/config): "--with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config"
build.nokogiri
Set for your local app (/Users/ruslan/3commas/3commas/.bundle/config): "--use-system-libraries"
default
Set for the current user (/Users/ruslan/.bundle/config): "2.2.21"
force_ruby_platform
Set for your local app (/Users/ruslan/3commas/3commas/.bundle/config): true
Set for the current user (/Users/ruslan/.bundle/config): true
github.https
Set for the current user (/Users/ruslan/.bundle/config): "true"

也许有人知道如何解决这个问题?非常感谢!🙏

我想知道这是否是一个与Gemfile.lock文件有关的问题,该文件可以有明确的平台进行绑定。您可以通过在该文件中查找PLATFORMS进行检查。

如果你通过bundler将苹果的ARM平台添加到你的设置中,这可能有助于捆绑正确版本的nokogiri?尝试在命令行上运行以下命令:

bundle lock --add-platform arm64-darwin-21

最新更新