无法在OSX 10.6上加载此类文件 - mechanise.rb(LoadError)

时间:2013-02-24 04:11:58

标签: ruby rvm mechanize-ruby

我有一个简单的脚本:

require 'rubygems'
require 'mechanize'
p 'Success!'

当我运行脚本时,我得到:

/Users/.../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mechanize.rb (LoadError)
from /Users/.../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test.rb:2:in `<main>'

在绝望中我安装了RVM并从系统1.8.7更新了ruby。然而,我仍然遇到与安装rvm之前相同的错误。我现在正在跑步:

mute:nfg ..$ ruby -v
ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-darwin10.8.0]

irb报告相同:

1.9.3p385 :001 > require 'rubygems'
 => false 
1.9.3p385 :002 > require 'mechanize'
LoadError: cannot load such file -- mechanize
from /Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):2
from /Users/../.rvm/rubies/ruby-1.9.3-p385/bin/irb:16:in `<main>'

我已经从项目目录中多次使用sudo重新安装了机械化。

我试过手动要求宝石及其完整路径。

mute:nfg ..$ ruby -l ~/.gems/gems/mechanize-2.5.1/lib/mechanize.rb
/Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mime/types (LoadError)
from /Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/../.gems/gems/mechanize-2.5.1/lib/mechanize.rb:4:in `<main>'

(我也试过安装mime-types。)

RVM列出了精美的宝石:

mute:nfg ..$ rvm all do gem list
*** LOCAL GEMS ***
...
libxml-ruby (2.3.3, 1.1.2)
mechanize (2.5.1)
mime-types (1.21, 1.19)
...

和宝石一样:

mute:nfg ..$ gem list
*** LOCAL GEMS ***
...
libxml-ruby (2.3.3, 1.1.2)
mechanize (2.5.1)
mime-types (1.21, 1.19)
...

奇怪的是,$ GEM_PATHs ~/.rvm/gems/ruby-1.9.3-p385~/.rvm/gems/ruby-1.9.3-p385@global~/.rvm/gems/ruby-1.9.3-p385@project大部分都是空的(第一个中有两个宝石,最后一个中没有宝石)。但是,GUI JewelleryBox确认所有三个gemset都包含Mechanize

编辑:这是gem env的结果:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.9.3 (2013-02-06 patchlevel 385) [x86_64-darwin10.8.0]
  - INSTALLATION DIRECTORY: /Users/../.gems
  - RUBY EXECUTABLE: /Users/../.rvm/rubies/ruby-1.9.3-p385/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/../.gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-10
  - GEM PATHS:
     - /Users/../.gems
     - /Users/../.gem
     - /usr/lib/ruby/gems/1.8
     - /Library/Ruby/Gems/1.8
     - /usr/bin
  - GEM CONFIGURATION:
 - :update_sources => true
 - :verbose => true
 - :benchmark => false
 - :backtrace => false
 - :bulk_threshold => 1000
 - :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
 - "gemhome" => "/Users/../.gems"
 - "gempath" => ["/Users/../.gem", "/usr/lib/ruby/gems/1.8", "/Library/Ruby/Gems/1.8", "/usr/bin"]
- REMOTE SOURCES:
 - http://gems.rubyforge.org/
 - http://gems.github.com

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

您的环境设置为使用宝石的自定义路径,这会在您安装到PATH

中不可用的地方时混淆rubygems

运行rvm get head并仔细阅读输出,它会警告您*gemrc中违反rubygems / RVM的条目