让nokogiri使用libxml2的新版本



我一直在尝试将Nokogiri安装在我的计算机(Mountain Lion)上,以便与rspec和capybara一起使用,但是对于我的生命,我无法使它正常运行。

据我所知,问题是nokogiri使用了错误的libxml2版本。到目前为止,我已经尝试使用Homebrew卸载和重新安装libxml2(确保它是最新的),使用bundle卸载和重新安装nokogiri,并指定安装nokogiri gem时Homebrew安装的libxml2文件的确切路径。我最近的安装说明是这样的

sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28

,其中所有这些位置都正确对应于工具的安装位置。但是,在运行bundle exec rspec spec/requests/static_pages.rb时,我仍然得到这样的输出:

/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `require': dlopen(/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/lib/libxml2.2.dylib (LoadError)
Referenced from: /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
Reason: Incompatible library version: nokogiri.bundle requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `<top (required)>'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
    from /Users/alex/Sites/harbingernews/config/application.rb:7:in `<top (required)>'
    from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `require'
    from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `<top (required)>'
    from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `require'
    from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `<top (required)>'
    from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `require'
    from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'

我已经尝试了我在网上找到的所有步骤(大多数参考构建和加载不同版本的libxml2,比如这个),但是还没有成功。我的Gemfile和Gemfile。锁可以在这里找到。如果有人能帮助我,我将非常感激。

在Mavericks中,使用brew安装库并在安装gem之前设置NOKOGIRI_USE_SYSTEM_LIBRARIES=1对我来说很有效。

总结:

  • 如果以前安装过,请卸载gem:
    $ gem uninstall nokogiri

  • 使用Homebrew安装libxml2, libxsltlibiconv:
    $ brew install libxml2 libxslt libiconv

  • 安装gem,指定要链接的库的路径:
    $ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

这有助于我更新libxml和安装nokogiri正确…

  1. 卸载nokogiri libxml-ruby
  2. 酿造更新
  3. brew uninstall libxml2 brew install libxml2——with-xml2-config
  4. brew link——force libxml2
  5. 安装libxslt
  6. brew link——force libxslt
  7. bundle config buildNokogiri -- --with-xml2-dir=/usr——with-xslt-dir =/opt/当地——with-iconv-dir =/opt/
  8. 包安装

来源:http://www.kormoc.com/2013/12/22/nokogiri-libxml2/

说明一下,Phrogz的评论对我帮助很大。我按照他链接到的指示,如果libxml2是一个混蛋该怎么办?Nokogiri的Github页面页。我最终使用Macports而不是Homebrew,我不确定这是否是造成差异的原因(我已经尝试了许多这些步骤),但不管怎样,它现在似乎工作得很好。

在升级OsX后搜索了这个问题:

require': dlopen(/Users/tomi/.rvm/gems/ruby-2.1.1@my-gemset/extensions/x86_64-darwin-12/2.1.0-static/nokogiri-1.5.10/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/opt/libxml2/lib/libxml2.2.dylib (LoadError)

这对我有效

brew uninstall libxml2 libxslt libiconv brew install libxml2 libxslt libiconv

相关内容

  • 没有找到相关文章

最新更新