Ruby require 'tk' 产生 LoadError: no such file to load -- tk [英] Ruby require 'tk' yields LoadError: no such file to load -- tk

查看:74
本文介绍了Ruby require 'tk' 产生 LoadError: no such file to load -- tk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让 ruby​​ 成功要求'tk'.我正在使用 rvm、ruby 2.0.0、ActiveTcl-8.6 和 Ubuntu 12.04 LTS.我已经运行了 ActiveTcl 提供的 wish 并且它似乎正在工作.

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.

我查看了 RVM 网站 http://rvm.io/integration/tk以及一些类似这样的 StackOverflow 问题RVM Ruby with TK installation (OSX).

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).

我在不同版本的 ruby​​ 上尝试了 rvm 重新安装 2.0.0 --enable-shared --enable-pthread --with-tk --with-tcl 几次,但没有成功.

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.

有什么想法吗?

当我运行 irb 并执行 require'tk' 时,我得到以下信息:

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>'

当这有效时,我认为您应该返回 true.

When this works I think you should get true returned.

我没有尝试其他任何东西,主要是因为我不知道还能做什么.我一直在研究 require 是如何工作的,并使用 ruby -e '$:' 检查加载路径,我得到

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.

根据路径问题的想法,我在我的文件中找到了 tk.rb 并在 irb 中尝试了以下内容:

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>'

所以现在是在 tk.rb 文件中 require 'tcltklib' 导致了问题.这似乎证实 $PATH 或 $load_path 存在一些问题.但是搜索文件 tcltklib.rb 没有结果.有一个 tcltklib.c 文件.

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.

我尝试了更多的东西.在通过 rvm 更仔细地阅读 ruby​​ 安装的输出后,有一个关于未安装 X11 库的警告,并且在 ruby​​ 构建后 Tk 不会处于活动状态.我做了 sudo apt-get install libx11-dev 然后 rvm 重新安装 2.0.0 --enable-shared --enable-pthread --with-tk --with-tcl 再说一次.这次在 irb require 'tk' 引起了核心转储.我又试了一次,它奏效了.然后我运行了一个简短的 ruby​​ 脚本,它也使用了 require 'tk'.它也核心转储,但经过几次尝试后工作.现在它对两者都有影响,有时有效,有时核心转储.

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.

推荐答案

不是只有 sudo apt-get install tk 就足够了,但您还需要安装以下库文件,以便您的问题得到解决而您不会看到这个再也不会出错了.

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

$ sudo apt-get install libtcltk-ruby

谢谢KK

这篇关于Ruby require 'tk' 产生 LoadError: no such file to load -- tk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆