[英]Ruby 2.0.0 cannot load such file even though gem is installed
I've tried all of the other solutions people have talked about on here, but none of them have helped / applied. 我已经尝试过人们在这里讨论过的所有其他解决方案,但是都没有帮助/应用过。
I've written a Ruby script that requires the spreadsheet gem. 我编写了一个需要电子表格gem的Ruby脚本。 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.... 当我使用
ruby myscript.rb
正常执行脚本时,但在运行chmod +x myscript.rb
,然后尝试使用./myscript.rb
运行程序时, ./myscript.rb
正常运行,我得到以下错误。
/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>'
The beginning of my script looks like this: 我的脚本的开头看起来像这样:
#!/usr/bin/ruby
require 'rubygems'
require 'spreadsheet'
If anyone has any ideas, I would really appreciate it. 如果有人有任何想法,我将不胜感激。
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
. 从您对评论的回答来看,您正在正常运行的红宝石-因此也就是安装宝石的宝石-/
/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
So that's using whichever ruby version you have installed in /usr/bin/ruby
. 因此,无论您使用的是
/usr/bin/ruby
安装的任何Ruby版本,都可以使用该版本。 In order to use your rbenv ruby instead of /usr/bin/ruby
, change the shebang line to: 为了使用您的rbenv红宝石而不是
/usr/bin/ruby
,将shebang行更改为:
#!/usr/bin/env ruby
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.