为什么我无法加载 Nokogiri? [英] Why can't I load Nokogiri?

查看:92
本文介绍了为什么我无法加载 Nokogiri?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过运行安装了 Nokogiri,没有任何问题:

I installed Nokogiri without any issues by running:

$ sudo gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.5.9
1 gem installed
Installing ri documentation for nokogiri-1.5.9...
Installing RDoc documentation for nokogiri-1.5.9...

当我运行 nokogiri.rb 时:

When I run nokogiri.rb:

#!/usr/bin/ruby -w

require 'nokogiri'

puts "Current directory is: #{ Dir.pwd }"
Dir.chdir("/home/askar/xml_files1") do |dirname|

  puts "Now in: #{ Dir.pwd }"
  xml_files = Dir.glob("ShipmentRequest*.xml")

  if xml_files.empty?
    puts "#{ dirname } is empty."
  else
    xml_files.each do |file|
      doc = Nokogiri::XML(open(file))
      # ... do something with the doc ...
    end
  end
end

我收到错误:

$ ruby nokogiri.rb 
/home/askar/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- nokogiri (LoadError)
  from /home/askar/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

我使用的是 Ruby 1.9.3,但出于某种原因,它指的是 Ruby 1.9.1.这可能是原因吗?

I'm using Ruby 1.9.3, but for some reason it refers to Ruby 1.9.1. Can this be the cause?

推荐答案

仔细观察,路径以/home/askar/.rvm/rubies/ruby-1.9.3-p429开头所以加载路径应该是正确的.

If you observe closely, the path starts with /home/askar/.rvm/rubies/ruby-1.9.3-p429 so the load path should be correct.

您的问题是您使用了 sudo 它将为系统 ruby​​ 安装 gem.不使用 sudo 再试一次,只需

Your problem is that you used sudo which will do a gem installation for the system ruby. Try again without sudo, just

gem install nokogiri

为当前的 rvm ruby​​ 安装 gem.

to install gems for the current rvm ruby.

这篇关于为什么我无法加载 Nokogiri?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆