How do I correctly use the Ruby Tk module? - ruby

I'm currently trying to create a basic GUI application in Ruby using the Tk module. Whenever I attempt to require the module (as tk or tcltklib), I get the following LoadError:
LoadError (126: The specified module could not be found. - C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tcltklib.so)
Currently, I have:
Installed Tcl (ActiveTcl) from the ActiveState website, specifically the 8.5.18.0 version for Windows (x86).
Installed Ruby with RubyInstaller for Windows, specifically Ruby+Devkit 2.5.3-1 (x86). The MSYS2 development toolchain was also selected to be installed, and all 3 components were chosen during ridk install.
Run gem install tk. The RubyInstaller changelog notes that, as of version 2.4.1-1, tk is no longer part of the standard library but can still be installed with gem install tk.
Attempted to require 'tk' and require 'tcltklib' in IRB and received the error above.
When running the following through IRB
require 'tk'
The output is
Traceback (most recent call last):
8: from C:/Ruby25/bin/irb:11:in `<main>'
7: from (irb):3
6: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
5: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
4: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
3: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tk.rb:7:in `<top (required)>'
2: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
1: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
LoadError (126: The specified module could not be found. - C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tcltklib.so)
The referenced file (C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tcltklib.so) does in fact exist though and this error seems different to the one output when requiring a non-existent module.
There seems to be very little information on this specific error, in fact, the only related things I could find were 10 year old posts on the Ruby forum which didn't yield much information.

Related

Restclient throwing unusual exception

While trying to use the following gems:
require 'nokogiri'
require 'restclient'
require 'mechanize'
I'm getting the following error:
C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ffi_c (LoadError)
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/ffi-1.9.10-x86-mingw32/lib/ffi.rb:6:in `rescue in <top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/ffi-1.9.10-x86-mingw32/lib/ffi.rb:3:in `<top (required)>'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/windows/root_certs.rb:2:in `<top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/windows.rb:7:in `require_relative'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/windows.rb:7:in `<top (required)>'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient.rb:16:in `<top (required)>'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from parse_docs.rb:5:in `<main>'
Since the last thing on this list is line 5, which is require 'restclient' I'm guessing it has something to do with that? However I've attempted to do the following:
Since restclient is deprecated and has moved to rest-client, I tried using rest-client however that doesn't work and produces the same error.
I've also attempted to require 'rubygems' but that when I run the program, it will not allow me to continue and produces the same error.
So I completely took out restclient, this is how I got the idea that restclient is causing the problem , because without it there, the program can run successfully.
So I though what would happen if I rolled back on ffi? So I installed the ffi version that is needed to run restclient However, that didn't help either.
Updated all my gems, still throwing the same error..
Downloaded the latest version on ffi, nothing changes, except now I havea new version of ffi on my system, that's still throwing an error when being used with restclient
Why is restclient producing the ffi error, I've never had this happen to me before. Is rest-client deprecated? Or is there a simple solution that I'm not catching onto? I've researched this, and nobody has had this problem (while using restclient) however there is a ton of people who have gotten this error while using other gems. For example see also here. It might also be worth mentioning that I'm running Windows 7.
The error comes after the ffi tries to load its C extension. If we have a look at the source code of the FFI gem, it tries to load the compiles extension according to the version of Ruby currently running:
begin
require RUBY_VERSION.split('.')[0, 2].join('.') + '/ffi_c'
rescue Exception
require 'ffi_c'
end
The first part fails so it falls back to the require 'ffi_c' which also fails. The problem now is that the first part should not fail.
In your case, it seems you are using a FFI gem which was compiled for another version of Ruby. Unfortunately, ruby has changes its ABI during releases so this doesn't work.
Thus, you need to make sure you are either using the pre-compiled gem matching your ruby version (which might be hard to find) or compiling it yourself. For that, please install the Development Kit for your Ruby version (towards the bottom left of the page). Then, you can install the ffi gem and force it to compile the C-extension on installation:
gem install ffi --platform=ruby
This is required as gem install ffi (without the --platform parameter), rubygems first tries to install the gem variant specific to your platform, i.e. mingw32 in your case, which is available in pre-compiled from from rubygems.org. Unfortunately, this precompiled gem apparently is incompatible with your version of Ruby. As such, you can force rubygems to get the source-version of the gem and compile the C-extension on its own. This is what you are instructing rubygems to do with the --platform=ruby argument.
This matches the description in the issues on FFI's issue tracker.
So I found an answer to this, it had to do with Holger Just's answer with a minor tweak, I'm pretty sure my case is pretty unique because my company likes to hide behind a VPN script. So here's how I did it:
First I needed to install the pre-release gem of ffi using the platform flag: gem install ffi --pre --platform=ruby
Next I had to update the gem: gem update --all (I think that's the correct syntax for the flag)
That got ffi working.

Ruby gamebox can't find the file gosu.for_1_9.so even though it's right there

Preface: I'm on a Windows 8 box, running Ruby 2.0.0.
I recently installed the gamebox gem for Ruby. During the installation of all its dependencies, a few files, among them the file $RUBYHOME/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so, did not build properly because of some ASCII/Unicode issues in rdoc, and were thus "skipped". I hadn't payed much attention to it initially, but when I tried to run gamebox test_game to setup a new gamebox game, it spat the following message at me:
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:118:in `require': 126: The specified module could not be found. - C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so (LoadError)
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:118:in `rescue in require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:124:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.rb:11:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:114:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:114:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gamebox-0.5.0/lib/gamebox.rb:5:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:66:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:66:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gamebox-0.5.0/bin/gamebox:4:in `<top (required)>'
from C:/Ruby200/bin/gamebox:23:in `load'
from C:/Ruby200/bin/gamebox:23:in `<main>'
The important bit there is The specified module could not be found. - C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so
I then went back and realized the whole Unicode thing, updated rdoc to the newest version as per this guy, and ran gem uninstall gosu followed by gem install gosu. Everything seemed to build just fine, and I saw that the needed file, .../gosu.for_1_9.so, was right where it needed to be.
However, I am still getting exactly the same error about not being able to find gosu.for_1_9.so!
I've been able to find exactly two Google results where someone else had this issue. In one situation the problem was peripheral because the guy was hacking on his gosu installation a bit; in the other, the solution was "Ruby 2 is bad and you should use Ruby 1.9", which is really not my preferred option.
Any ideas?
Ken,
The file is being found, but is not compatible to load in Ruby 2.0.0.
This is a bug / missing feature of Gosu. It does not work with Ruby 2.0.0 on Windows. The author of the gem has plans to work this out, but has not yet tackled it. You can follow up on the issue on Github here: https://github.com/jlnr/gosu/issues/163
The author can be found on freenode IRC in #gosu. I'm sure they could use some help with their windows support. Unfortunately, the answer to using Gamebox on Windows is to downgrade to Ruby 1.9.3. I will add this to the Gamebox wiki.
I agree with #Shawn42
But probably the best way is to install beforehand a ruby version manager.
RVM with Pik is what I use on Windows.
That way you can install the older 1.9.3 version of ruby and call pik to use that version whenever you want to use gamebox. You'll still have ruby 2.0.0 installed and ready to be used for your other projects.
http://www.ruby-on-rails-outsourcing.com/articles/2010/07/28/ruby-version-manager-for-windows/
Cheers

ruby error on windows 7 x64

install ruby 1.9.3, devkit, mingw
gem install rails work good, but when i create new rails app - have bundler error
D:/Programes/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 193: %1 эх  ты хЄё  яЁшыюцхэшхь Win32. - D:/Programes/Ruby193/lib/ruby/1.9.1/i386-mingw32/digest/sha1.so (LoadError)
from D:/Programes/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/definition.rb:1:in `<top (required)>'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:138:in `definition'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/cli.rb:219:in `install'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/vendor/thor/task.rb:22:in `run'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/vendor/thor.rb:263:in `dispatch'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/vendor/thor/base.rb:386:in`start'
from D:/Programes/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/bin/bundle:13:in `<main>'
and commands like
D:\Work\ruby>gem help commands
ERROR: Loading command: server (LoadError)
193: %1 эх  ты хЄё  яЁшыюцхэшхь Win32. - D:/Programes/Ruby193/lib/ruby/1.9.1/i386-mingw32/digest/md5.so
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::ServerCommand
file md5.so exists
what i forgot to do and may ruby don`t work on windows 7 x64?
I think you use cyrillic without # encoding: UTF-8, just add it to file where you use эх ты...
P.S.: откуда вообще там кирилица?
Also running Windows 7 x64, and I had this same problem crop up on me with 1.9.3-p0. Searched the web without success. Also tried copying in the "sha1.so" file from 1.9.2-p290 in case it was a problem with that particular library -- nope.
I'd suggest something about rubygems or bundler seems to break require, but the same bundler and rubygems code runs fine on 1.9.2. I get no problem running require "digest/sha1"
in my own bare test file with Ruby 1.9.3.
Reverting to Ruby 1.9.2-p290 fixed the problem for me for the moment.

Problem using wxRuby

I am trying to create my first GUI using wxRuby. I installed wxRuby (using gem install wxruby-ruby19) and, it seemed to be installed alright. I copied some code directly from the wxRuby site. Here is the code I used:
test.rb
require "wx"
include Wx
class MinimalApp < App
def on_init
Frame.new(nil, -1, "The Bare Minimum").show()
end
end
MinimalApp.new.main_loop
When I ran it, I got this error:
<internal:lib/rubygems/custom_require>:29:in `require': libwx_gtk2u_stc-2.8.so.0: cannot open shared object file: No such file or directory - /usr/local/ruby/lib/ruby/gems/1.9.1/gems/wxruby-ruby19-2.0.1-x86-linux/lib/wxruby2.so (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/wxruby-ruby19-2.0.1-x86-linux/lib/wx.rb:12:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:33:in `require'
from <internal:lib/rubygems/custom_require>:33:in `rescue in require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from test.rb:2:in `<main>'
I thought it was saying that wxruby wasn't in that directory, but I checked and it was, so I'm not sure what the problem is. If anyone could help, that would be awesome.
I tried the same thing and got the same result.
It turns out that there are 2 wxRuby gems. If you are using Ruby 1.9x, you want wxRuby-ruby19. (gem install wxruby-ruby19).
I uninstalled the wxruby gem that I installed the first time (gem uninstall wxruby), and then installed the gem for my version of Ruby (gem install wxruby-ruby19). And Voila! All the sample code just worked. No additional downloads needed.
To use wxRuby you need wxWidgets installed (wxGTK in your case).
The problem is wxRuby uses the wxWidgets shared libraries (e.g. libwx_gtk2u_stc-2.8.so.0) and it cant find them.

"undefined method path" error installing RubyGems

I have installed Ruby v1.9.2, and (according to the instructions on http://rubyonrails.org/download) I am trying to install Gems. I've downloaded the 1.4.2 zip from http://rubyforge.org/frs/?group_id=126, but when I run setup.rb, I get the following error/trace:
C:\temp\rubygemsInstall\rubygems-1.4.2\rubygems-1.4.2>setup.rb
C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems/source_index.
rb:62:in `installed_spec_directories': undefined method `path' for Gem:Module (N
oMethodError)
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems/
source_index.rb:52:in `from_installed_gems'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems.
rb:914:in `source_index'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems/
gem_path_searcher.rb:83:in `init_gemspecs'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems/
gem_path_searcher.rb:13:in `initialize'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems.
rb:873:in `new'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems.
rb:873:in `searcher'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems.
rb:495:in `find_files'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems.
rb:1034:in `load_plugins'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/lib/rubygems/
gem_runner.rb:84:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/temp/rubygemsInstall/rubygems-1.4.2/rubygems-1.4.2/setup.rb:25:i
n `<main>'
I am running Windows Server 2008 R2 - please post a comment if there is any other relevant info.
How do I get around this error?
The windows RubyInstaller includes rubygems already, so you don't have to install it separately. I'm assuming you're using RubyInstaller because that's what the rubyonrails.org page links you to if you click on the Windows link, but there is more information on the RubyInstaller page in the Help section.
What happens if you go to a cmd prompt and do "gem list"?
Older versions of rubygems aren't completely compatible with Ruby 1.9.2. I realize the OP discovered that rubygems was already installed, but for those who still need to install it, all you need to do is downgrade to Ruby 1.8.7 and then it should work properly. This is where a tool like RVM really comes in handy.

Resources