gem query finds gem, yet require fails

Discussion in 'Ruby' started by Michael Glaesemann, Nov 12, 2006.

  1. I'm setting up a secondary machine to run tests. I've run into a
    problem with gems not being found. Everything works fine on my
    primary machine, and I haven't been able to tease out what the
    difference is in the two setups.

    I've installed Ruby 1.8.5 and rubygems 0.9.0, both from source, on
    Mac OS X 10.4.8.
    Ruby configuraiton:
    $ ./configure --prefix=/usr/local

    rubygems installation:
    $ sudo /usr/local/bin/ruby setup.rb

    I installed the PostgreSQL bindings gem using:
    $ sudo gem install postgres

    The bindings appeared to install correctly. Using gem query, I can see:


    *** LOCAL GEMS ***

    postgres (0.7.1)
    The extension library to access a PostgreSQL database from Ruby.

    sources (0.0.1)
    This package provides download sources for remote gem installation

    However, when testing with irb to see if the postgres gem can be
    found, I get:

    $ which ruby
    /usr/local/bin/ruby
    $ which irb
    /usr/local/bin/irb
    $ irb
    irb(main):001:0> require 'rubygems'
    => true
    irb(main):002:0> require 'postgres'
    LoadError: no such file to load -- postgres
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
    custom_require.rb:27:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
    custom_require.rb:27:in `require'
    from (irb):2

    I'm stumped. On my primary machine, the above two commands work just
    fine in irb.

    Looking around custom_require.rb and seeing the private init_gemspecs
    method, I tried:
    irb(main):006:0> gs = Gem::GemPathSearcher.new
    ...
    irb(main):017:0> pp gs.send:)init_gemspecs)

    I can see the postgres gem included in the list (relevant part of the
    output is posted below).

    However, the find method fails:

    irb(main):018:0> gs.find('postgres')
    => nil

    The default dir appears to be correct:

    irb(main):020:0> Gem.default_dir
    => "/usr/local/lib/ruby/gems/1.8"

    In the shell:
    $ ls -la /usr/local/lib/ruby/gems/1.8
    total 4040
    drwxr-xr-x 7 root wheel 238 Nov 12 22:11 .
    drwxr-xr-x 3 root wheel 102 Nov 12 22:10 ..
    drwxr-xr-x 11 root wheel 374 Nov 12 22:24 cache
    drwxr-xr-x 10 root wheel 340 Nov 12 22:24 doc
    drwxr-xr-x 11 root wheel 374 Nov 12 22:24 gems
    -rw-r--r-- 1 root wheel 2066469 Nov 12 22:12 source_cache
    drwxr-xr-x 11 root wheel 374 Nov 12 22:24 specifications

    Any help would be appreciated. I've been staring at this for quite a
    while now and nothing new is coming to me. I don't have any GEM_*
    environmental variables or .gemrc files on either machine. Anything
    else I should try or check?

    Thanks!

    Michael Glaesemann
    grzm seespotcode net

    ### partial init_gemspecs output
    #<Gem::Specification:0x585ffc
    @authors=[],
    @autorequire="postgres",
    @bindir="bin",
    @cert_chain=nil,
    @date=Wed Oct 20 00:00:00 +0900 2004,
    @default_executable=nil,
    @dependencies=[],
    @email="",
    @executables=[],
    @extensions=["extconf.rb"],
    @extra_rdoc_files=[],
    @files=
    ["ChangeLog",
    "doc",
    "extconf.rb",
    "MANIFEST",
    "postgres-ruby.gemspec",
    "postgres.c",
    "README",
    "README.ja",
    "sample",
    "doc/postgres.html",
    "doc/postgres.jp.html",
    "sample/losample.rb",
    "sample/psql.rb",
    "sample/psqlHelp.rb",
    "sample/test1.rb",
    "sample/test2.rb",
    "sample/test4.rb"],
    @has_rdoc=false,
    @homepage="http://www.postgresql.jp/interfaces/ruby/",
     
    Michael Glaesemann, Nov 12, 2006
    #1
    1. Advertising

  2. On Nov 12, 2006, at 23:28 , Michael Glaesemann wrote:


    > The bindings appeared to install correctly. Using gem query, I can
    > see:
    >
    >
    > *** LOCAL GEMS ***
    >
    > postgres (0.7.1)
    > The extension library to access a PostgreSQL database from Ruby.
    >
    > sources (0.0.1)
    > This package provides download sources for remote gem installation
    >
    > However, when testing with irb to see if the postgres gem can be
    > found, I get:
    >
    > $ which ruby
    > /usr/local/bin/ruby
    > $ which irb
    > /usr/local/bin/irb
    > $ irb
    > irb(main):001:0> require 'rubygems'
    > => true
    > irb(main):002:0> require 'postgres'
    > LoadError: no such file to load -- postgres
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
    > custom_require.rb:27:in `gem_original_require'
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
    > custom_require.rb:27:in `require'
    > from (irb):2
    >
    > I'm stumped. On my primary machine, the above two commands work
    > just fine in irb.


    Any ideas at all on this? I'm really stuck. Or perhaps how to make
    sure I've completely uninstalled Ruby and rubygems so I can maybe try
    installing again?

    As an aside, how could I make this message more likely to get a
    response? I seem to have lost my knack.

    Thanks for any suggestions on either issue :)

    Michael Glaesemann
    grzm seespotcode net
     
    Michael Glaesemann, Nov 14, 2006
    #2
    1. Advertising

  3. Michael Glaesemann

    Jan Svitok Guest

    On 11/14/06, Michael Glaesemann <> wrote:
    >
    > On Nov 12, 2006, at 23:28 , Michael Glaesemann wrote:
    >
    >
    > > The bindings appeared to install correctly. Using gem query, I can
    > > see:
    > >
    > >
    > > *** LOCAL GEMS ***
    > >
    > > postgres (0.7.1)
    > > The extension library to access a PostgreSQL database from Ruby.
    > >
    > > sources (0.0.1)
    > > This package provides download sources for remote gem installation
    > >
    > > However, when testing with irb to see if the postgres gem can be
    > > found, I get:
    > >
    > > $ which ruby
    > > /usr/local/bin/ruby
    > > $ which irb
    > > /usr/local/bin/irb
    > > $ irb
    > > irb(main):001:0> require 'rubygems'
    > > => true
    > > irb(main):002:0> require 'postgres'
    > > LoadError: no such file to load -- postgres
    > > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
    > > custom_require.rb:27:in `gem_original_require'
    > > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
    > > custom_require.rb:27:in `require'
    > > from (irb):2
    > >
    > > I'm stumped. On my primary machine, the above two commands work
    > > just fine in irb.

    >
    > Any ideas at all on this? I'm really stuck. Or perhaps how to make
    > sure I've completely uninstalled Ruby and rubygems so I can maybe try
    > installing again?
    >
    > As an aside, how could I make this message more likely to get a
    > response? I seem to have lost my knack.
    >
    > Thanks for any suggestions on either issue :)
    >
    > Michael Glaesemann
    > grzm seespotcode net


    Hi,

    [I don't know anything about neither OSX nor postgres gem]

    - it seems you have require patched, so gems are in the game. that's fine.
    - postgres from the listing seems to have compiled extension. Check
    whether it is indeed compiled - you'll have postgres.so somewhere in
    the dir. If it's not there look for info how to setup build
    environment
    - check whether the ext is directly in lib or somewhere deeper - i.e.
    require 'whatever/postgres'
    - go there, try require it from the dir where it is without rubygems
    if you can't the problem is somewhere deeper.

    For example, on debian&co you have to have installed build-essential
    package. Without it, the ext won't be compiled however gem will
    install fine and don't tell anything.
     
    Jan Svitok, Nov 14, 2006
    #3
  4. On Nov 15, 2006, at 0:55 , Jan Svitok wrote:

    > - it seems you have require patched, so gems are in the game.
    > that's fine.


    Thanks for confirming that. Good to have a second opinion.

    > - postgres from the listing seems to have compiled extension. Check
    > whether it is indeed compiled - you'll have postgres.so somewhere in
    > the dir. If it's not there look for info how to setup build
    > environment


    This is very helpful. I hadn't thought to check this. I can see that
    there *is* a postgres.o on the system that works, but it's missing on
    the system that doesn't. This gives me something to pursue.

    > - check whether the ext is directly in lib or somewhere deeper - i.e.
    > require 'whatever/postgres'
    > - go there, try require it from the dir where it is without rubygems
    > if you can't the problem is somewhere deeper.
    >
    > For example, on debian&co you have to have installed build-essential
    > package. Without it, the ext won't be compiled however gem will
    > install fine and don't tell anything.


    From the system where it works, the postgres.o file is in the top-
    level of the postgres-0.7.1 directory (i.e., /usr/local/lib/ruby/gems/
    1.8/gems/postgres-0.7.1/postgres.o) so this is probably not a
    problem, but it's also something for me to check when I figure out
    why the postgres.o file isn't getting built.

    Thanks for the pointers, Jan. This is really helpful, and gives me
    something to work on :)

    Michael Glaesemann
    grzm seespotcode net
     
    Michael Glaesemann, Nov 15, 2006
    #4
  5. Michael Glaesemann

    Jan Svitok Guest

    On 11/15/06, Michael Glaesemann <> wrote:
    >
    > On Nov 15, 2006, at 0:55 , Jan Svitok wrote:
    >
    > > - it seems you have require patched, so gems are in the game.
    > > that's fine.

    >
    > Thanks for confirming that. Good to have a second opinion.
    >
    > > - postgres from the listing seems to have compiled extension. Check
    > > whether it is indeed compiled - you'll have postgres.so somewhere in
    > > the dir. If it's not there look for info how to setup build
    > > environment

    >
    > This is very helpful. I hadn't thought to check this. I can see that
    > there *is* a postgres.o on the system that works, but it's missing on
    > the system that doesn't. This gives me something to pursue.
    >
    > > - check whether the ext is directly in lib or somewhere deeper - i.e.
    > > require 'whatever/postgres'
    > > - go there, try require it from the dir where it is without rubygems
    > > if you can't the problem is somewhere deeper.
    > >
    > > For example, on debian&co you have to have installed build-essential
    > > package. Without it, the ext won't be compiled however gem will
    > > install fine and don't tell anything.

    >
    > From the system where it works, the postgres.o file is in the top-
    > level of the postgres-0.7.1 directory (i.e., /usr/local/lib/ruby/gems/
    > 1.8/gems/postgres-0.7.1/postgres.o) so this is probably not a
    > problem, but it's also something for me to check when I figure out
    > why the postgres.o file isn't getting built.
    >
    > Thanks for the pointers, Jan. This is really helpful, and gives me
    > something to work on :)


    Glad to help. Try googling for other compiled gems' problems on OSX -
    e.g. mysql, mongrel, rcov, ruby-prof.
     
    Jan Svitok, Nov 15, 2006
    #5
  6. Re: gem query finds gem, yet require fails [SOLVED]

    On Nov 15, 2006, at 9:26 , Michael Glaesemann wrote:

    >
    > On Nov 15, 2006, at 0:55 , Jan Svitok wrote:
    >
    >> - postgres from the listing seems to have compiled extension. Check
    >> whether it is indeed compiled - you'll have postgres.so somewhere in
    >> the dir. If it's not there look for info how to setup build
    >> environment

    >
    > This is very helpful. I hadn't thought to check this. I can see
    > that there *is* a postgres.o on the system that works, but it's
    > missing on the system that doesn't. This gives me something to pursue.


    I was able to install the postgres bindings by explicitly calling

    sudo ruby extconf.rb --with-pgsql-lib-dir=/usr/local/lib/ --with-
    pgsql-include-dir=/usr/local/include
    sudo make
    sudo make install

    Passing those same compilation flags through gem didn't work and I'm
    not sure why.

    sudo gem install postgres -- --with-pgsql-lib-dir=/usr/local/lib/ --
    with-pgsql-include-dir=/usr/local/include

    No errors were thrown; the source just didn't get compiled

    Thanks again, Jan, for your help!

    Michael Glaesemann
    grzm seespotcode net
     
    Michael Glaesemann, Nov 26, 2006
    #6
    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. Tim Verstraete
    Replies:
    1
    Views:
    597
    Mike Treseler
    Sep 12, 2005
  2. Berehem
    Replies:
    4
    Views:
    599
    Lawrence Kirby
    Apr 28, 2005
  3. Daniel Berger
    Replies:
    2
    Views:
    174
    Daniel Berger
    Sep 12, 2008
  4. Iñaki Baz Castillo
    Replies:
    3
    Views:
    166
    Iñaki Baz Castillo
    Feb 28, 2011
  5. Chris
    Replies:
    8
    Views:
    190
    Sisyphus
    May 19, 2005
Loading...

Share This Page