本文介绍了即使安装了gem,Ruby 2.0.0也不能加载这样的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了人们在这里讨论过的所有其他解决方案,但是他们都没有帮助/应用。

I've tried all of the other solutions people have talked about on here, but none of them have helped / applied.

我写了一个需要电子表格gem的Ruby脚本。当我通常使用 ruby​​ myscript.rb 执行脚本,但在运行 chmod + x myscript.rb ,然后试图用 ./ myscript.rb 运行程序。我得到以下错误....

I've written a Ruby script that requires the spreadsheet gem. The requiring works fine when I execute the script normally with ruby myscript.rb, but after running chmod +x myscript.rb, and then trying to run the program with ./myscript.rb I get the following error....

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- spreadsheet (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/parse.rb:2:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/fcangialosi/dev/mTC/interpreter.rb:1:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from ./pmcnp.rb:7:in `<main>'

我的脚本如下所示:

#!/usr/bin/ruby

require 'rubygems'
require 'spreadsheet'

如果有人有任何想法,我会非常感激。 / p>

If anyone has any ideas, I would really appreciate it.

推荐答案

从您对注释的回答中,您正常运行的ruby - 因此安装了您的宝石 - 是 /Users/fcangialosi/.rbenv/shims/ruby 。当您使脚本可执行时,它会使用脚本中的提示知道要使用哪个程序来执行脚本。在你的情况下,你有:

From your answers to the comments, the ruby you're running normally - and therefore the one in which your gems are installed - is /Users/fcangialosi/.rbenv/shims/ruby. When you make the script executable, it uses the hint in the script to know which program to use to execute the script. In your case, you have:

#!/usr/bin/ruby

这就是使用你安装在 / usr / bin / ruby​​ 中的任何一个ruby版本。为了使用rbenv ruby​​而不是 / usr / bin / ruby​​ ,将shebang行更改为:

So that's using whichever ruby version you have installed in /usr/bin/ruby. In order to use your rbenv ruby instead of /usr/bin/ruby, change the shebang line to:

#!/usr/bin/env ruby

这篇关于即使安装了gem,Ruby 2.0.0也不能加载这样的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 18:05