宝石发现在irb中,而不是在Ruby中 [英] Gem found in irb, not in Ruby

查看:96
本文介绍了宝石发现在irb中,而不是在Ruby中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  require'rubygems' 
require'mygem'

当我运行该应用程序时,出现此错误: < internal:lib / ruby​​gems / custom_require>:29:in require':no such file to load - mygem(LoadError)`



但是,如果我尝试在 irb 内部确保需要gem(确保首先需要'rubygems'),它可以正常工作。我应该做些什么?



> ruby​​ , gem irb 显示它们都在 / opt / local / bin / ,即

 > ruby 
/ opt / local / bin / ruby​​
>其中宝石
/ opt / local / bin / gem
>其中irb
/ opt / local / bin / irb

更新回答提出的问题是的,irb和ruby指向不同的文件夹):

$ LOAD_PATH $ :在irb中都包含似乎指向ruby 1.8的文件夹:

  / opt / local / lib / ruby​​ / site_ruby / 1.8 
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin10
/ opt / local / lib / ruby​​ / site_ruby
/ opt / local / lib / ruby​​ / vendor_ruby / 1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin10
/ opt / local / lib / ruby​​ / vendor_ruby
/ opt / local / lib / ruby​​ / 1.8
/opt/local/lib/ruby/1.8/i686-darwin10

$:在ruby中指向ruby 1.9 .1文件夹:

  /usr/local/lib/ruby/site_ruby/1.9.1 
/ usr / local /lib/ruby/site_ruby/1.9.1/i386-darwin9.8.0
/ usr / local / lib / ruby​​ / site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.8.0
/ usr / local / lib / ruby​​ / vendor_ruby
/usr/local/lib/ruby/1.9 .1
/usr/local/lib/ruby/1.9.1/i386-darwin9.8.0



code> gem env 显示

  RubyGems环境:
- RUBYGEMS VERSION:1.4.1
- RUBY VERSION:1.8.7(2010-12-23 patchlevel 330)[i686-darwin10]
- 安装目录:/ opt / local / lib / ruby​​ / gems /1.8
- RUBY EXECUTABLE:/ opt / local / bin / ruby​​
- 可执行目录:/ opt / local / bin
- RUBYGEMS平台:
- ruby​​
- x86-darwin-10
- 创业板路径:
- /opt/local/lib/ruby/gems/1.8
- 创业板配置:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- gempath=> [/opt/local/lib/ruby/gems/1.8]
- :sources => [http://rubygems.org/,http://gems.github.com,http://gems.github.com]
- 远程来源:
- http ://rubygems.org/
- http://gems.github.com
- http://gems.github.com

在irb中的Gem.path 指向

  /Users/grautur/.gem/ruby/1.8 
/usr/local/lib/ruby/gems/1.8

Gem.path 在ruby中指向



<$ p $ /> $ / $ / $ c $ / code /


解决方案

我不确定发生了什么事。然而,以下可能会有所帮助。



在irb中,做

  require'rubygems'
require'mygem'
puts $:

然后,在ruby中,做

  require'rubygems'
puts $:

并向我们展示如果您还没有完成工作,您会得到什么。

Edit:还会在命令行上输出执行 gem env 的结果。



编辑2:在irb和ruby都需要rubygems后,如果输入 puts Gem.path ,看看会发生什么。请参阅感谢Matt描述Rubygems


I have some gems installed, and I'm trying to use them in a Ruby app:

require 'rubygems'
require 'mygem'

When I run the app, though, I get this error: <internal:lib/rubygems/custom_require>:29:inrequire': no such file to load -- mygem (LoadError)`

But if I try requiring the gem inside irb (making sure to `require 'rubygems' first), it works fine. What am I supposed to do? I tried googling for this problem, but didn't understand.

Running a which on ruby, gem, and irb shows that they're all in /opt/local/bin/, i.e.,

> which ruby
/opt/local/bin/ruby
> which gem
/opt/local/bin/gem
> which irb
/opt/local/bin/irb

Update to answer the questions posed (yep, irb and ruby are pointing to different folders):

$LOAD_PATH and $: in irb both contain seem to be pointing to ruby 1.8 folders:

/opt/local/lib/ruby/site_ruby/1.8
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/site_ruby
/opt/local/lib/ruby/vendor_ruby/1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/vendor_ruby
/opt/local/lib/ruby/1.8
/opt/local/lib/ruby/1.8/i686-darwin10
.

$: in ruby points to ruby 1.9.1 folders:

/usr/local/lib/ruby/site_ruby/1.9.1
/usr/local/lib/ruby/site_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/1.9.1
/usr/local/lib/ruby/1.9.1/i386-darwin9.8.0

gem env shows

RubyGems Environment:
  - RUBYGEMS VERSION: 1.4.1
  - RUBY VERSION: 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
  - INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /opt/local/bin/ruby
  - EXECUTABLE DIRECTORY: /opt/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-10
  - GEM PATHS:
     - /opt/local/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gempath" => ["/opt/local/lib/ruby/gems/1.8"]
     - :sources => ["http://rubygems.org/", "http://gems.github.com", "http://gems.github.com"]
  - REMOTE SOURCES:
     - http://rubygems.org/
     - http://gems.github.com
     - http://gems.github.com

Gem.path in irb points to

/Users/grautur/.gem/ruby/1.8
/usr/local/lib/ruby/gems/1.8

Gem.path in ruby points to

/Users/grautur/.gem/ruby/1.9.1
/usr/local/lib/ruby/gems/1.9.1

解决方案

I'm not sure what's going on. However, the following may help.

In irb, do

require 'rubygems'
require 'mygem'
puts $:

and then, in ruby, do

require 'rubygems'
puts $:

and show us what you get if you haven't worked it out.

Edit: also print out the results of doing gem env on the command line.

Edit 2: See what happens if you type in puts Gem.path after you've required rubygems in both irb and ruby. See thanks to Matt for describing Rubygems

这篇关于宝石发现在irb中,而不是在Ruby中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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