Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby require 'tk' yields LoadError: no such file to load -- tk

Tags:

ruby

tk

I'm not able to get ruby to require 'tk' successfully. I'm using rvm, ruby 2.0.0, ActiveTcl-8.6, and Ubuntu 12.04 LTS. I have run wish provided with ActiveTcl and it seems to be working.

I've looked on the RVM site http://rvm.io/integration/tk and several StackOverflow questions like this one RVM Ruby with TK installation (OSX).

I have tried rvm reinstall 2.0.0 --enable-shared --enable-pthread --with-tk --with-tcl several times on different versions of ruby with no success.

Any thoughts?

When I run irb and do require'tk' I get the following:

LoadError: cannot load such file -- tk
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):2
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'

When this works I think you should get true returned.

I haven't tried anything else mainly because I can't figure out what else to do. I've been looking into how require works and checking the load path with ruby -e '$:' I get

[brooks@ubuntu:~/sites/depot]$ruby -e 'puts $:'
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/x86_64-linux
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/vendor_ruby/2.0.0
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/vendor_ruby/2.0.0/x86_64-linux
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/vendor_ruby
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux

This looks like what you would expect, I think. Sorry for the formatting, I'm new to the editor.

Following up on the idea that it's a path problem, I found tk.rb in my files and tried the following in irb:

2.0.0-p353 :003 > require '/home/brooks/.rvm/src/ruby-2.0.0-p353/ext/tk/lib/tk'   
LoadError: cannot load such file -- tcltklib
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/brooks/.rvm/src/ruby-2.0.0-p353/ext/tk/lib/tk.rb:6:in `<top (required)>'
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):3
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'

So now it's require 'tcltklib' in the tk.rb file that's causing the problem. This seems to confirm that there is some issue with $PATH or $load_path. But a search for the file tcltklib.rb turns up nothing. There is a tcltklib.c file.


I tried a few more things. After a more careful reading of the output of the ruby installs via rvm, there was a warning about the X11 lib not being installed and that Tk wouldn't be active after the ruby build. I did sudo apt-get install libx11-dev and then rvm reinstall 2.0.0 --enable-shared --enable-pthread --with-tk --with-tcl again. This time in irb require 'tk' caused a core dump. I tried it another time and it worked. I then ran a short ruby script that also uses require 'tk'. It also core dumped, but worked after a few tries. Now it's hit or miss for both, sometimes works, sometimes it core dumps.

like image 850
Brooks Childers Avatar asked Jan 02 '14 00:01

Brooks Childers


2 Answers

Not onty sudo apt-get install tk is enough but you also need the below library files to be installed so that your problem will be solved and you wont see this error never again.

$ sudo apt-get install libtcltk-ruby

thanks KK

like image 102
Kalyan Kumar Avatar answered Nov 14 '22 23:11

Kalyan Kumar


I met the same situation. I tried to track it like follows:

$cd ~/.rvm/src/ruby-2.1.1/ext/tk
$ruby extconf.rb

And then:

 check functions.checking for ruby_native_thread_p() in ruby.h... yes
.checking for rb_errinfo() in ruby.h... yes
.checking for rb_safe_level() in ruby.h... yes
.checking for rb_hash_lookup() in ruby.h... yes
.checking for rb_proc_new() in ruby.h... yes
.checking for rb_obj_untrust() in ruby.h... yes
.checking for rb_obj_taint() in ruby.h... yes
.checking for rb_set_safe_level_force() in ruby.h... yes
.checking for rb_sourcefile() in ruby.h... yes
.checking for rb_thread_alive_p() in ruby.h... no
.checking for rb_thread_check_trap_pending() in ruby.h... yes
.check struct members.checking for struct RArray.ptr in ruby.h... no
.checking for struct RArray.len in ruby.h... no
.check libraries.checking for t_open() in -lnsl... no
.checking for socket() in -lsocket... no
.checking for dlopen() in -ldl... yes
.checking for log() in -lm... yes
Use ActiveTcl libraries (if available).
Search tclConfig.sh and tkConfig.sh..
Ignore "/opt/ActiveTcl-8.6/lib/tclConfig-shared.sh" (unsupported version of Tcl/Tk).
Ignore "/opt/ActiveTcl-8.6/lib/tclConfig.sh" (unsupported version of Tcl/Tk).
..............................
Fail to find [tclConfig.sh, tkConfig.sh]
Use X11 libraries (or use TK_XINCLUDES/TK_XLIBSW information on tkConfig.sh).
checking for XOpenDisplay() in -lX11... yes

Search tcl.h.checking for tcl.h... no
.Search tk.h.checking for tk.h... no
.Search Tcl library...............
Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled        on your Ruby. That is, Ruby/Tk will not work). Please check configure options.
Can't find proper Tcl/Tk libraries. So, can't make tcltklib.so which is required by Ruby/Tk.
If you have Tcl/Tk libraries on your environment, you may be able to use them with configure options (see ext/tk/README.tcltklib).
At present, Tcl/Tk8.6 is not supported. Although you can try to use Tcl/Tk8.6 with configure options, it will not work correctly. I recommend you to use Tcl/Tk8.5 or 8.4.

Look at the last line: "At present, Tcl/Tk8.6 is not supported."

To resolve:

  1. Uninstall active-tcl8.6.1
  2. Install 8.5 or 8.4 , add install path to $PATH
  3. rvm reinstall ruby-2.1.1 --with-tcl --with-tk
like image 33
JoeWoo Avatar answered Nov 14 '22 23:11

JoeWoo