Problem when requiring 'Qt4' in Ruby 1.8.7 - ruby

I have successfully installed:
Ruby 1.8.7-p334
Rubygems 1.7.2
rake 0.9.0
qtruby4 2.1.0 mswin32
Now the following block of code
require 'rubygems'
require 'Qt4'
gives me an error:
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:926:in report_activate_error': RubyGem version error: qtruby4(2.1.0 not >= 0) (Gem::LoadError)
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:244:inactivate_dep'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:236:in activate'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:213:intry_activate'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:56:in `require'
from C:/Users/nick/Documents/NetBeansProjects/RubyApplication2/lib/main.rb:4
Everything good when requiring just 'rubygems'. My OS is Windows 7.

Make sure you require correct gem name
require 'Qt4' seems like little different as almost all the ruby gem names are in simple letters
isnt your gem name 'qtruby4' by any chance, if so try
require 'rubygems'
require 'qtruby4'
HTH
sameera

Related

Require order in a ruby script

I have a ruby script that requires 3 gems to work. My script starts as follows:
#!/usr/bin/env ruby
require 'httparty'
require 'imgkit'
require 'twitter'
Now, interestingly, the above code works, but only if I require httparty first or second. If I require it as the third dependency, I get the following:
'require': cannot load such file -- httparty (LoadError)
I'd love to learn why this is happening, so I can better understand how ruby handles gem dependencies. Many thanks!
Edit: I am using bundler. This is my Gemfile:
source 'https://rubygems.org'
ruby '2.2.2'
gem 'wkhtmltoimage-binary'
gem 'imgkit'
gem 'twitter'
gem 'rspec'
gem 'httparty'
Following tadman's advice, adding require 'bundler/setup' solved the problem. More in the docs. Thanks!

Bunder require yaml/logger

I am using bundler to require all the gems in my project. However, it's not working for yaml/logger.
If I add gem 'yaml' to my gemfile, and run bundle install, I get:
Could not find gem 'yaml (>= 0) ruby' in the gems available on this machine.
But I require it normally just fine. What am I doing wrong?
Thanks
YAML is part of the Ruby Standard Library, and not a Gem.
You do not need to add it to your Gemfile, just require it.
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> YAML
=> Psych
The same applies for Logger.

Ruby not finding gems, but they appear on gem list, and work in irb console?

I've got a Ruby app using deamon-kit to create a daemon that runs a cron task every 3 seconds.
Problem is I'm trying to add some error checking using Errbit, so that requires me to:
require 'hoptoad_notifier'
in my script. However, the script is complaining it can't find the file?
.rvm/gems/ruby-1.9.2-p320#stitch/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require': no such file to load -- hoptoad_notifier (LoadError)
What confuses me is that the gem is installed, when I run
gem list | grep hoptoad_notifier
I get
hoptoad_notifier (2.4.11)
Another test I did was to pop into irb console, on the same terminal window, after making sure I'm inside the correct RVM gemset off course:
1.9.2p320 :001 > require 'hoptoad_notifier'
=> true
1.9.2p320 :002 >
And voila, hoptoad is loading. It's only when loading my deamon-kit deamon, that I get the error.
What further confuses me is that when I look at my require block:
require 'rubygems'
require 'resque'
require 'hoptoad_notifier'
It's finding rubygems and resque, but not hoptoad_notifier? Why, when I comment out hoptoad, it doesn't also complain about resque and rubygems?
dameon-kit uses bundler, so you don't need to include rubygems. Include the following lines to your Gemfile :
gem 'resque'
gem 'hoptoad_notifier'
Run bundle install
and include your gems as usual :
require 'resque'
require 'hoptoad_notifier'
It worked for me.

Problems with ruby 'unroller' gem

I'm having a problem using unroller. I have installed the gem and wrote this simple program to help focus on the problem i'm having:
#!/usr/bin/ruby
require 'rubygems'
require 'unroller'
Unroller::trace
def foo(p1, p2)
puts p1
puts p2
end
foo("param1", "param2")
Running the program yields:
/Library/Ruby/Gems/1.8/gems/facets-2.9.3/lib/core/facets/filetest/separator_pattern.rb:5: warning: already initialized constant SEPARATOR_PATTERN
/Library/Ruby/Gems/1.8/gems/facets-2.9.3/lib/core/facets/string/bracket.rb:3: warning: already initialized constant BRA2KET
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- facets/methodspace (LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
from /Library/Ruby/Gems/1.8/gems/unroller-1.0.0/lib/unroller.rb:4
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from ./ut:4
My ruby version is ruby 1.8.7 (2011-12-28 patchlevel 357). I also installed ruby on my Windows development box and get the same error and that ruby version is 1.9.3 so it does not appear to be related to the version of Ruby I'm on.
Anyone have any ideas?
Thanks very much in advance!
jon
This is a bug of unroller gem, described here: https://github.com/TylerRick/unroller/issues/1. unroller automatically requires the latest version of facets gem and the version 2.9 breaks it. (BTW gems should never use '>=' when loading dependencies, that's why '~>' is for.)
It's not that difficult to hotfix locally by using bundler and hardcoding facets gem to specific version before requiring unroller (so the specific facets version gets loaded instead of latest 2.9).
create Gemfile:
source 'http://rubygems.org'
gem 'facets', '2.8.4'
gem 'termios' # you're gonna need this gem too, for some reason
gem 'unroller'
run bundle install and then either run the script by bundle exec ruby test.rb or require bundler/setup in it:
require 'rubygems'
require 'bundler/setup'
require 'unroller'
...
UPDATE: or if you don't wanna deal with bundler, try this first, it could work too:
require 'rubygems'
gem 'facets', '2.8.4'
require 'unroller'
...

Missing gem watir?

ahmet#Ubuntu:~/test$ ruby hello.rb
/home/ahmet/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- watir (LoadError)
from /home/ahmet/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from hello.rb:2:in `<main>'
I have required rubygems in my .rb but still get this error
require 'rubygems'
require 'watir'
According to Watir Readme you have to install and require firewatir. Also you may want to install watir-webdriver instead.
I encountered a similar problem with a different gem a while back on Ubuntu using RVM. I know the gem was installed, because I had just installed it. I did the following:
rvm get latest
rvm reload
gem update --system
Then for good measure I reinstalled the gem, and everything worked. Hope this helps you as well.
Read this: https://github.com/zeljkofilipin/watirbook/blob/master/installation/ubuntu.md
The require should be either 'firewatir' or 'watir-webdriver'
require 'firewatir'
or
require 'watir-webdriver'

Resources