Weird action of 'nokogiri' library on Snow Leopard

cut the introduction.. here is my situation on the snow leopard.

$ cat d.rb
require 'nokogiri'

$ ruby d.rb
d.rb:1:in `require': no such file to load -- nokogiri (LoadError)
  from d.rb:1

$ irb

require 'nokogiri'

=> true

quit

I can just execute and load 'nokogiri' library only on irb not A
source.

what's problems on my situation?

any helps?

Most likely because you do not require rubygems in your script. Snow
Leopard's default irbrc (in /etc/irbrc) takes care of that for you.

Add a "require 'rubygems'" above your "require 'nokogiri'" and you
should be fine.,

Ben

···

On Fri, Feb 5, 2010 at 10:35 AM, junyoung <juneng603@gmail.com> wrote:

I can just execute and load 'nokogiri' library only on irb not A
source.

what's problems on my situation?

$ cat d.rb

require 'rubygems' # missing this :slight_smile:

···

On Fri, Feb 5, 2010 at 10:35 AM, junyoung <juneng603@gmail.com> wrote:

require 'nokogiri'

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

Okay ben, thanks for your replay.

it makes my script working. but, I am still wondering why it didn't
work.

I installed the library by using gems. why I have to load 'rubygems'
library also before calling 'nokogiri'??

···

On 2월6일, 오전3시43분, Ben Bleything <b...@bleything.net> wrote:

On Fri, Feb 5, 2010 at 10:35 AM, junyoung <juneng...@gmail.com> wrote:
> I can just execute and load 'nokogiri' library only on irb not A
> source.

> what's problems on my situation?

Most likely because you do not requirerubygems

rubygems in your script. Snow
Leopard's default irbrc (in /etc/irbrc) takes care of that for you.

Add a "require 'rubygems'" above your "require 'nokogiri'" and you
should be fine.,

Ben

Because that is how it works :slight_smile:

RubyGems is a packaging system. It works by manipulating Ruby's load
path to include the lib directories of any gems you have installed...
but to make that work, you must include RubyGems in your script.
Starting with Ruby 1.9, RubyGems is built-in to Ruby, so you won't
need to do that any more, but while you're using Ruby 1.8, you'll need
to require rubygems whenever you want to use a gem.

As an alternative, you can set the environment variable RUBYOPT to 'rubygems':

[11:24:29] ben@folio (master)
~ $ cat d.rb
require 'nokogiri'
puts "nokogiri loaded successfully"

[11:24:34] ben@folio (master)
~ $ ruby d.rb
d.rb:1:in `require': no such file to load -- nokogiri (LoadError)
  from d.rb:1

[11:24:36] ben@folio (master)
~ $ export RUBYOPT="rubygems"

[11:24:42] ben@folio (master)
~ $ ruby d.rb
nokogiri loaded successfully

···

2010/2/5 Jun Young <juneng603@gmail.com>:

it makes my script working. but, I am still wondering why it didn't
work.

I installed the library by using gems. why I have to load 'rubygems'
library also before calling 'nokogiri'??

you make me clear, ben.
thanks :slight_smile:

···

On 2월6일, 오전4시25분, Ben Bleything <b...@bleything.net> wrote:

2010/2/5 Jun Young <juneng...@gmail.com>:

> it makes my script working. but, I am still wondering why it didn't
> work.

> I installed the library by using gems. why I have to load 'rubygems'
> library also before calling 'nokogiri'??

Because that is how it works :slight_smile:

RubyGems is a packaging system. It works by manipulating Ruby's load
path to include the lib directories of any gems you have installed...
but to make that work, you must include RubyGems in your script.
Starting with Ruby 1.9, RubyGems is built-in to Ruby, so you won't
need to do that any more, but while you're using Ruby 1.8, you'll need
to require rubygems whenever you want to use a gem.

As an alternative, you can set the environment variable RUBYOPT to 'rubygems':

[11:24:29] ben@folio (master)
~ $ cat d.rb
require 'nokogiri'
puts "nokogiri loaded successfully"

[11:24:34] ben@folio (master)
~ $ ruby d.rb
d.rb:1:in `require': no such file to load -- nokogiri (LoadError)
  from d.rb:1

[11:24:36] ben@folio (master)
~ $ export RUBYOPT="rubygems"

[11:24:42] ben@folio (master)
~ $ ruby d.rb
nokogiri loaded successfully

May i seek your help for captioned case ?
I am test the script named test.rb by command "ruby test.rb" and it
pass.
Then i converte it as rake task.
The rake task pass on rails 2.3.5 but fail on rails 3 beta4 with error
msg:
"no such file to load -- nokogiri"

···

============================
env :rails 3 beta4, ruby 1.8.7, ubuntu

test.rb

require 'rubygems'
require 'nokogiri'
require 'open-uri'
require "iconv"

   url = "http://www.bugutang.com"
   doc = Nokogiri::HTML(open(url))
     doc.css("title").each do |c|
     puts Iconv.iconv("GBK//IGNORE", "UTF-8//IGNORE", c.content)

    end

claw.rake

desc "Fetch product "
task :claw => :environment do
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require "iconv"

   url = "http://www.bugutang.com"
   doc = Nokogiri::HTML(open(url))
     doc.css("title").each do |c|
     puts Iconv.iconv("GBK//IGNORE", "UTF-8//IGNORE", c.content)

    end
end

here is the environment :
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /home/bugu/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/
*** LOCAL GEMS ***

nokogiri (1.4.2)
    Authors: Aaron Patterson, Mike Dalessio
    Rubyforge: http://rubyforge.org/projects/nokogiri
    Homepage: http://nokogiri.org
    Installed at: /usr/lib/ruby/gems/1.8

Any help ?

Ben Bleything wrote:

2010/2/5 Jun Young <juneng603@gmail.com>:

it makes my script working. but, I am still wondering why it didn't
work.

I installed the library by using gems. why I have to load 'rubygems'
library also before calling 'nokogiri'??

Because that is how it works :slight_smile:

RubyGems is a packaging system. It works by manipulating Ruby's load
path to include the lib directories of any gems you have installed...
but to make that work, you must include RubyGems in your script.
Starting with Ruby 1.9, RubyGems is built-in to Ruby, so you won't
need to do that any more, but while you're using Ruby 1.8, you'll need
to require rubygems whenever you want to use a gem.

As an alternative, you can set the environment variable RUBYOPT to
'rubygems':

[11:24:29] ben@folio (master)
~ $ cat d.rb
require 'nokogiri'
puts "nokogiri loaded successfully"

[11:24:34] ben@folio (master)
~ $ ruby d.rb
d.rb:1:in `require': no such file to load -- nokogiri (LoadError)
  from d.rb:1

[11:24:36] ben@folio (master)
~ $ export RUBYOPT="rubygems"

[11:24:42] ben@folio (master)
~ $ ruby d.rb
nokogiri loaded successfully

--
Posted via http://www.ruby-forum.com/\.