Ruby requires "tk" gives LoadError: there is no such file to load - tk

I can not get ruby ​​before , requiring "tk" . I am using rvm, ruby ​​2.0.0, ActiveTcl-8.6 and Ubuntu 12.04 LTS. I ran a wish with ActiveTcl and it seems to work.

I looked at the RVM website http://rvm.io/integration/tk and a few StackOverflow questions such as RVM Ruby with TK (OSX) installation .

I tried rvm reinstalling 2.0.0 --enable-shared -enable-pthread -with-tk -with-tcl several times in different versions of ruby ​​without success.

Any thoughts?

When I run irb and execute 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 need to return true .

I have not tried anything else because I cannot figure out what else to do. I watched how to work and check the boot path using 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 is similar to what you expect, I think. Sorry for the formatting, I'm new to the editor.

Following the idea that this is 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 tcltklib is required in the tk.rb file, which causes the problem. This seems to confirm that there is a problem with $ PATH or $ load_path. But a search for the tcltklib.rb file does not cause anything. There is a tcltklib.c file.


I tried a few more things. After a more thorough reading of the output of the ruby ​​installation via rvm, a warning appeared that X11 lib was not installed and that Tk would not 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, irb requires 'tk' , which caused a core dump. I tried again and it worked. Then I ran a short ruby ​​script that also uses require 'tk' . It also dropped kernels, but worked after several attempts. Now it hit or missed for both, sometimes it works, sometimes it resets the kernels.

+6
source share
3 answers

Sudo apt-get install tk is not enough, but you also need the installed library files below so that your problem is resolved and you no longer see this error.

$ sudo apt-get install libtcltk-ruby

thanks KK

+5
source

I met the same situation. I tried to track this as 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. 

Take a look at the last line: "Tcl / Tk8.6 is not currently supported."

To solve:

  • Delete active-tcl8.6.1
  • Install 8.5 or 8.4, add the installation path to $PATH
  • rvm reinstall ruby-2.1.1 --with-tcl --with-tk
+3
source

On Mac OSX 10.6.8, the reorientation of active-tcl to version 8.5 worked for me.

  • Remove active-tcl8.6

    See: http://docs.activestate.com/activetcl/8.5/at.install.html

    After directions do not work there, read the note below for directions:

    Note. On Snow Leopard and above, an installation script is installed under /Library/Frameworks/Tcl.framework/Versions//Resources/Scripts/uninstall instead. Apple reorganized the directories for storing receipts and removed the space for third-party files from it.

    But this will not work either, so see here:

    Remove Active TCL Mac

  • Install active-tcl8.5

    See here: http://www.activestate.com/activetcl/downloads

    I did not need to do anything with my $ PATH.

  • rvm reinstall ruby-2.1.2 --with-tcl --with-tk

+2
source

All Articles