ruby - 为什么找不到库: no such file to load

标签 ruby require

我卡住了,找不到原因,应该很简单,

这是错误信息:

require': no such file to load -- ./ip (LoadError)

它是由这行代码生成的:

require './ip'

作为 需要“套接字” 有效,我找到了两个库:

/usr/lib/ruby/gems/1.8/gems/ruby-ip-0.9.1/lib/ip.rb
/usr/lib/ruby/gems/1.8/gems/ruby-ip-0.9.1/lib/ip/socket.rb

也尝试过需要'ip'需要'../ip'

还是一样的错误


背景信息:

我安装了 ruby​​-ip,这样我就可以调用如下方法:ip = IP.new do ...

gem installed ruby-ip

我可以看到库(我相信这是我需要使用的 ip.rb;

pwd
/usr/lib/ruby/gems/1.8/gems/ruby-ip-0.9.1/lib
ls
ip ip.rb

环境信息

ruby -v
ruby 1.8.7 (2012-10-12 patchlevel 371) [i386-linux]

gem list

*** LOCAL GEMS ***

builder (3.2.0)
eventmachine (1.0.1, 0.12.10)
pg (0.14.1, 0.13.2)
ruby-ip (0.9.1)
rubygems-update (2.0.0)
sqlite3 (1.3.3)

哪个 ruby

/usr/bin/ ruby

哪个 gem

/usr/bin/gem

gem 环境

RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.0
  - RUBY VERSION: 1.8.7 (2012-10-12 patchlevel 371) [i386-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /home/pilar/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

最佳答案

您是否也包括 require 'rubygems'?如果您使用 rvm,则这是必需的。

例子:

[fotanus@thing ~]$ gem install ip
Fetching: ip-0.3.0.gem (100%)
Successfully installed ip-0.3.0
1 gem installed
Installing ri documentation for ip-0.3.0...
Installing RDoc documentation for ip-0.3.0...
[fotanus@thing ~]$ irb
1.8.7 :001 > require 'ip'
LoadError: no such file to load -- ip
    from (irb):1:in `require'
    from (irb):1
1.8.7 :002 > require 'rubygems'
 => true 
1.8.7 :003 > require 'ip'
 => true 
1.8.7 :004 > 

关于ruby - 为什么找不到库: no such file to load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15194433/

相关文章:

php - 是否有像 ruby​​ 调试器一样的 php 交互式调试器?

ruby - 未定义方法 `-' 对于 nil :NilClass (NoMethodError)

ruby - 使用 rspec 测试生产特定代码 - Sinatra

html - 在 Nokogiri 中访问 HTML 属性

javascript - 在 ES6 导入中重写 require ('shipit-deploy' )(shipit) 之类的东西?

ruby-on-rails - `rails s` 表示 "` 在 Windows RailsInstaller 中需要 ': cannot load such file -- pty (LoadError)"

header - 如何用 Lua 语言创建包含文件?

javascript - 在 node.js 中重新映射 require() 的本地路径

lua 要求如何工作

java - lein 编译问题 (Clojure)