When trying to run the following code I am getting an error which says
“no such file to load — openâ€uri”
require ‘rubygems’
require ‘mechanize’
require ‘nokogiri’
require ‘openâ€uri’
def scrapePage(url, file)
agent = WWW::Mechanize.new
page = agent.get(url)
pp page
#…
end
scrapePage(‘http://google.com’, ‘dump.txt’)
I have the latest version of Xcode, other details below.
Ruby Version: ruby 1.8.7 (2008-08-11 patchlevel 72)
[universal-darwin10.0]
OS: OS X 10.6.2
Thanks
Nabs K. wrote:
When trying to run the following code I am getting an error which says
“no such file to load — openâ€uri”
…
require ‘openâ€uri’
Try just
ruby -ropen-uri -e0
If that gives you the same error, then it looks like your ruby
installation is broken or incomplete, since it’s a standard part of the
core library.
$ ls -l /usr/lib/ruby/1.8/open-uri.rb
-rw-r–r-- 1 root root 20982 2007-10-08 12:16
/usr/lib/ruby/1.8/open-uri.rb
(This is under Ubuntu Linux rather than Mac, and the ruby version is
1.8.7p174, but open-uri.rb has been in ruby for years)
Are you sure you haven’t got something odd like an em-dash instead of a
proper hyphen?
Quick Update: If I run the program via IRB it works fine, but if I try
to run the program via the Terminal command ruby ‘codeFile.rb’ then it
gives the same error… So, that means it is not isolated to TextMate as
I was thinking earlier…
Brian, thanks for the response. I don’t get any error upon running “ruby
-ropen-uri -e0” in terminal… so I assume that means something is wrong
with path variables? Also, I should have mentioned that I have been
running this in TextMate.
After this I tried to run the same program via Terminal and it works
fine… so it is a TextMate issue… any ideas where I should start to
solve it in TextMate?
Thanks,
Nabs K.
Brian C. wrote:
Nabs K. wrote:
When trying to run the following code I am getting an error which says
“no such file to load — openâ€uri”
…
require ‘openâ€uri’
Try just
ruby -ropen-uri -e0
If that gives you the same error, then it looks like your ruby
installation is broken or incomplete, since it’s a standard part of the
core library.
$ ls -l /usr/lib/ruby/1.8/open-uri.rb
-rw-r–r-- 1 root root 20982 2007-10-08 12:16
/usr/lib/ruby/1.8/open-uri.rb
(This is under Ubuntu Linux rather than Mac, and the ruby version is
1.8.7p174, but open-uri.rb has been in ruby for years)
Are you sure you haven’t got something odd like an em-dash instead of a
proper hyphen?
Nabs K. wrote:
Quick Update: If I run the program via IRB it works fine, but if I try
to run the program via the Terminal command ruby ‘codeFile.rb’ then it
gives the same error… So, that means it is not isolated to TextMate as
I was thinking earlier…
Perhaps you have two different versions of ruby. Try running these in
both ways:
ruby -v
ruby -e ‘require “rbconfig”; puts Config::CONFIG[“rubylibdir”]’
ruby -e ‘puts $:.inspect’
On my box these give respectively:
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
/usr/lib/ruby/1.8
["/usr/local/lib/site_ruby/1.8",
“/usr/local/lib/site_ruby/1.8/x86_64-linux”, “/usr/local/lib/site_ruby”,
“/usr/lib/ruby/vendor_ruby/1.8”,
“/usr/lib/ruby/vendor_ruby/1.8/x86_64-linux”,
“/usr/lib/ruby/vendor_ruby”, “/usr/lib/ruby/1.8”,
“/usr/lib/ruby/1.8/x86_64-linux”, “.”]
The rubylibdir is where I’d expect open-uri.rb to be found.