importing GEM libraries .... newby questions

Discussion in 'Ruby' started by cugf_0956, Mar 26, 2007.

  1. cugf_0956

    cugf_0956 Guest

    I have installed ruby on my laptop using rpm and I installed a whole
    bunch of packages using GEM. Now when I run any scripts on my laptop,
    ruby can locate any package that is installed via rpm but not the one
    installed via GEM. How can I make it work such that everything that is
    installed using Gem can be seen by ruby.
    Here is an example:
    I have
    /usr/lib/ruby/1.8/date
    I can call "require date" in my script and it will work.

    I have
    /usr/lib/ruby/gems/1.8/gems/Selenium-1.0.1/bin/selenium

    when I call "require selenium" it doesn't work.
    What is the catch here?

    Also, if I want to package my scripts to run on somebody else machine,
    how can I make it, if he/she has right packages installed, can run my
    scripts without errors?

    And one more question, I know that Perl can be pre-compiled for better
    performance, can ruby scripts be pre-compiled as well?

    Thanks a lot.

    --
    Posted via http://www.ruby-forum.com/.
    cugf_0956, Mar 26, 2007
    #1
    1. Advertising

  2. cugf_0956 wrote:
    > I have installed ruby on my laptop using rpm and I installed a whole
    > bunch of packages using GEM. Now when I run any scripts on my laptop,
    > ruby can locate any package that is installed via rpm but not the one
    > installed via GEM. How can I make it work such that everything that is
    > installed using Gem can be seen by ruby.
    > Here is an example:
    > I have
    > /usr/lib/ruby/1.8/date
    > I can call "require date" in my script and it will work.
    >
    > I have
    > /usr/lib/ruby/gems/1.8/gems/Selenium-1.0.1/bin/selenium
    >
    > when I call "require selenium" it doesn't work.
    > What is the catch here?
    >
    > Also, if I want to package my scripts to run on somebody else machine,
    > how can I make it, if he/she has right packages installed, can run my
    > scripts without errors?
    >
    > And one more question, I know that Perl can be pre-compiled for better
    > performance, can ruby scripts be pre-compiled as well?
    >
    > Thanks a lot.
    >
    >

    You need to have RubyGems loaded before you require any libraries that
    were installed using RubyGems. You can do this:

    export RUBYOPT=rubygems

    or in every script that requires a gem, require 'rubygems' before
    requiring any gem.
    Timothy Hunter, Mar 26, 2007
    #2
    1. Advertising

  3. cugf_0956

    Brad Sherard Guest

    Timothy Hunter wrote:
    > cugf_0956 wrote:
    >> Thanks a lot.
    >> [...]

    > You need to have RubyGems loaded before you require any libraries that
    > were installed using RubyGems. You can do this:
    >
    > export RUBYOPT=rubygems
    >
    > or in every script that requires a gem, require 'rubygems' before
    > requiring any gem.


    I have the exact problem cugf described right down to using the same gem
    (selenium). I tried your first suggestion but that returned with a
    compile time error. I've wasted a day digging through google links
    without any luck but maybe I was searching for the wrong things. Here is
    what I have:

    C:\Documents and Settings\user>gem contents selenium

    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/bin/selenium
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/button.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/directory_listing_page.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/link.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/locator.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/selenium_server.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/server_manager.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/text_field.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/version
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/README
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/selenium-server.jar.txt
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/selenium.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/download_page.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/home_page.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/menu.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/tc_basic_operation.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/tc_selenium_server.rb
    c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/README

    And the (very unhelpful) example selenium provides has the following
    requires:

    require 'spec'
    $:.unshift File.join(File.dirname(__FILE__), '..')
    require 'lib/selenium'

    I have no idea how to figure out what to require so I have to assume the
    example is exhaustive and correct. However, just using the lines above
    errors out on the first require with the reason: no such file to load.
    If it is a problem of not having rubygems loaded, would someone mind
    very much elaborating a bit on the 'export RUBYOPT=rubygems' stuff?
    Also, is there a way to discern what values should be specified in the
    require lines for a given installed gem? Is there a way to just require
    individual .rb files? In advance, thank you to anyone with information.
    Normally I wouldn't dare asking such simple questions but I cannot
    figure this out.

    --
    Posted via http://www.ruby-forum.com/.
    Brad Sherard, Mar 26, 2007
    #3
  4. On Tue, Mar 27, 2007 at 03:34:09AM +0900, Brad Sherard wrote:
    > > You need to have RubyGems loaded before you require any libraries that
    > > were installed using RubyGems. You can do this:
    > >
    > > export RUBYOPT=rubygems
    > >
    > > or in every script that requires a gem, require 'rubygems' before
    > > requiring any gem.

    >
    > I have the exact problem cugf described right down to using the same gem
    > (selenium). I tried your first suggestion but that returned with a
    > compile time error.


    There is no "compile time" in Ruby.

    Post the snippet of code you were trying to run, and the exact error
    message.

    > C:\Documents and Settings\user>gem contents selenium
    >
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/bin/selenium
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/button.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/directory_listing_page.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/link.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/locator.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/selenium_server.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/server_manager.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/text_field.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/version
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/README
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/selenium-server.jar.txt
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/selenium.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/download_page.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/home_page.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/menu.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/tc_basic_operation.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/tc_selenium_server.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/README
    >
    > And the (very unhelpful) example selenium provides has the following
    > requires:
    >
    > require 'spec'
    > $:.unshift File.join(File.dirname(__FILE__), '..')
    > require 'lib/selenium'


    As suggested by earlier posters, try:

    require 'rubygems'
    require 'selenium'

    and if it doesn't work, post the entire error message you see.

    Brian.
    Brian Candler, Mar 26, 2007
    #4
  5. Brad Sherard wrote:
    > Timothy Hunter wrote:
    >
    >> cugf_0956 wrote:
    >>
    >>> Thanks a lot.
    >>> [...]
    >>>

    >> You need to have RubyGems loaded before you require any libraries that
    >> were installed using RubyGems. You can do this:
    >>
    >> export RUBYOPT=rubygems
    >>
    >> or in every script that requires a gem, require 'rubygems' before
    >> requiring any gem.
    >>

    >
    > I have the exact problem cugf described right down to using the same gem
    > (selenium). I tried your first suggestion but that returned with a
    > compile time error. I've wasted a day digging through google links
    > without any luck but maybe I was searching for the wrong things. Here is
    > what I have:
    >
    > C:\Documents and Settings\user>gem contents selenium
    >
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/bin/selenium
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/button.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/directory_listing_page.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/link.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/locator.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/selenium_server.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/server_manager.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/text_field.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/version
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/README
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/selenium-server.jar.txt
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/openqa/selenium.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/download_page.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/home_page.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/menu.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/tc_basic_operation.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/tc_selenium_server.rb
    > c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/README
    >
    > And the (very unhelpful) example selenium provides has the following
    > requires:
    >
    > require 'spec'
    > $:.unshift File.join(File.dirname(__FILE__), '..')
    > require 'lib/selenium'
    >
    > I have no idea how to figure out what to require so I have to assume the
    > example is exhaustive and correct. However, just using the lines above
    > errors out on the first require with the reason: no such file to load.
    > If it is a problem of not having rubygems loaded, would someone mind
    > very much elaborating a bit on the 'export RUBYOPT=rubygems' stuff?
    > Also, is there a way to discern what values should be specified in the
    > require lines for a given installed gem? Is there a way to just require
    > individual .rb files? In advance, thank you to anyone with information.
    > Normally I wouldn't dare asking such simple questions but I cannot
    > figure this out.
    >
    >

    Libraries installed by RubyGems must be loaded by RubyGems. RubyGems
    does this by replacing the standard "require" method with its own
    version. To make this happen though, rubygems.rb must be required by the
    normal require method. So, the simplest (although least satisfactory)
    thing to do is require "rubygems" before requiring anything else.

    require "rubygems" # uses normal require method, adds its own require
    method
    require "somegem" # uses RubyGems require

    Make sense? Okay. You can of course require a library on the command
    line using the -r option:

    ruby -r rubygems myprog.rb

    The space between -r and rubygems is not necessary:

    ruby -rrubygems myprog.rb

    Somebody smart on the RubyGems team realized that they could create a
    file called "ubygems.rb" and then you could run Ruby like this:

    ruby -rubygems myprog.rb

    Still with me? One more step. You can specify Ruby options in the
    RUBYOPT environment variable. Since these options aren't on the command
    line, they don't need the little "-" in front to distinguish them from
    non-option things.

    export RUBYOPT=rubygems

    is the same thing as "-rubygems". You'll probably want to put the export
    command in your .profile file (assuming you're on a *nix-like system).
    If you're on Windows, set environment variables using Control
    Panel->System (iirc).

    Lastly, once you've ensured that rubygems is loaded, all you need to do
    is require the .rb file you need. RubyGems takes care of figuring out
    where it's at so you don't need to.

    Here's the scoop on RubyGems: http://docs.rubygems.org/read/book/1
    Timothy Hunter, Mar 26, 2007
    #5
  6. cugf_0956

    Brad Sherard Guest

    Timothy Hunter wrote:
    > Brad Sherard wrote:
    >>> export RUBYOPT=rubygems

    >>
    >> c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/lib/selenium/selenium_server.rb
    >> c:/ruby/lib/ruby/gems/1.8/gems/Selenium-1.0.1/spec/selenium/tc_basic_operation.rb
    >> I have no idea how to figure out what to require so I have to assume the
    >>


    > Here's the scoop on RubyGems: http://docs.rubygems.org/read/book/1


    Excellent Tim! I owe you my soul or something for all that help. Thanks!

    --
    Posted via http://www.ruby-forum.com/.
    Brad Sherard, Mar 26, 2007
    #6
  7. cugf_0956

    Eric Hodel Guest

    On Mar 25, 2007, at 20:26, cugf_0956 wrote:

    > I have installed ruby on my laptop using rpm and I installed a whole
    > bunch of packages using GEM. Now when I run any scripts on my laptop,
    > ruby can locate any package that is installed via rpm but not the one
    > installed via GEM. How can I make it work such that everything that is
    > installed using Gem can be seen by ruby.


    You must require rubygems first. You can set RUBYOPT=-rubygems in
    your shell environment to make sure rubygems is always loaded.
    Eric Hodel, Mar 27, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcello Pietrobon

    Two newby's questions

    Marcello Pietrobon, Feb 24, 2004, in forum: Python
    Replies:
    3
    Views:
    268
    Mark 'Kamikaze' Hughes
    Mar 4, 2004
  2. plb
    Replies:
    2
    Views:
    315
  3. Routb3d
    Replies:
    4
    Views:
    1,490
    Isaiah Coberly
    Feb 27, 2010
  4. Austin 7873
    Replies:
    5
    Views:
    171
    Eric Hodel
    Jan 27, 2007
  5. Renato
    Replies:
    5
    Views:
    90
    Renato Vernucio
    Feb 17, 2014
Loading...

Share This Page