简体   繁体   English

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

[英]Can't use Nokogiri gem on M1 processor

I have a problem with using the M1 processor and Nokogiri gem.我在使用 M1 处理器和 Nokogiri gem 时遇到问题。

Gemfile宝石文件

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

When I run bundle install , all seems good, but when I try to run specs, for example, I see the error:当我运行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

I've tried to install Nokogiri with gem install nokogiri -v 1.13.6 --platform arm64-darwin , and now it looks like that:我尝试使用gem install nokogiri -v 1.13.6 --platform arm64-darwin ,现在看起来像这样:

nokogiri -versions : 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

But when I try to run specs with this version only, I have an error:但是,当我尝试仅使用此版本运行规范时,出现错误:

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

So to avoid this error, I have to install Nokogiri through bundle install , but it installs the wrong version, not for the arm platform, and then I have a problem with the platform.所以为了避免这个错误,我必须通过bundle install安装 Nokogiri,但是它安装了错误的版本,不是针对 arm 平台的,然后我的平台有问题。 If I install Nokogiri through the gem install command, the bundler doesn't see it.如果我通过gem install命令安装 Nokogiri,捆绑器看不到它。

My bundle config :我的捆绑配置

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"

Maybe somebody knows how to figure out this problem?也许有人知道如何解决这个问题? Many thanks in advance!提前谢谢了!

I wonder if this is an issue related to the Gemfile.lock file, which can have explicit platforms to bundle for.我想知道这是否是与Gemfile.lock文件相关的问题,该文件可以有明确的平台来捆绑。 You can check by looking for PLATFORMS within that file.您可以通过在该文件中查找PLATFORMS来进行检查。

If you add Apple's ARM platform to your setup via bundler, that may help the correct version of nokogiri to be bundled?如果您通过捆绑程序将 Apple 的 ARM 平台添加到您的设置中,这可能有助于捆绑正确版本的 nokogiri? Try running the following on the command line:尝试在命令行上运行以下命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM