【问题标题】:`require': cannot load such file -- curses (LoadError)`require': 不能加载这样的文件——curses (LoadError)
【发布时间】:2018-10-16 02:36:28
【问题描述】:

我是一名 ruby​​ 初学者,正在努力理解和学习 ruby​​。我在尝试运行使用“require curses”的 ruby​​ 文件时遇到了这个错误,但这样做时出现以下错误。任何帮助或提示表示赞赏。

desktop$ ruby curses.rb 
/desktop/jsipp-master$ gem list

*** LOCAL GEMS ***

bigdecimal (1.2.8)
CFPropertyList (2.2.8)
curses (1.2.4)
did_you_mean (1.0.0)
enumerate (0.0.7)
enumerated (1.0.1)
enumeration (1.3.3)
ffi (1.9.25)
ffi-rzmq (2.0.6)
ffi-rzmq-core (1.0.6)
io-console (0.4.5)
json (1.8.3)
libxml-ruby (2.9.0)
minitest (5.8.5)
net-telnet (0.1.1)
nokogiri (1.5.6)
power_assert (0.2.6)
psych (2.1.0)
rake (10.4.2)
rdoc (4.2.1)
sqlite3 (1.3.11)
test-unit (3.1.5)

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- curses (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from curses.rb:3:in `<main>'

   jsipp-master$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]

#!/usr/bin/ruby

require 'curses'
require 'ffi-rzmq'
require 'enumerator'

POSITIONS = "%15s %8s %8s %12s %12s %12s\n"
POSITIONS2 = "%-38s %-38s\n"
POSITIONS3 = "%15s %-12s%%-10s%%-10s%%-10s%%-15s\n"

OUT_ARROW = "-------->"
IN_ARROW = "<--------"
PAUSE =    "[%6dms]"

class MinuteLongBuffer
  def initialize
    @values = []
  end

  def add v
    @values << [Time.new.to_f, v]
  end

  def count
    @values = @values.keep_if {|v| v[0] > (Time.new.to_f - 1)}
    @values.length
  end
end

class Scenario
  def parse_scenario_desc desc
    @strings = []
    @msg_counts = []
    parts = desc.split(";")
    parts.each do |part|
      type, value = part.split(":")
      if type == "IN"
        @strings << (POSITIONS3 % [value, IN_ARROW])
      elsif type == "OUT"
        @strings << (POSITIONS3 % [value, OUT_ARROW])
      elsif type == "PAUSE"
        @strings << (POSITIONS3 % [(PAUSE % value), ""])
      end
      @msg_counts << 0
      @unexpected_msg_counts << 0
      @timeout_counts << 0
    end
  end

  def inc_msg idx
    @msg_counts[idx.to_i] += 1
    if idx.to_i == 0
      @new_calls.add 1
    end
  end

  def inc_unexpected idx
    @unexpected_msg_counts[idx.to_i] += 1
  end

  def inc_timeout idx
    @timeout_counts[idx.to_i] += 1
  end

  def update
    Curses.clear
    Curses.addstr(POSITIONS % ["Call-rate", "Length", "Port", "Total-time", "Total-calls", "Remote-host"])
    Curses.addstr(POSITIONS % [("?cps"), "? ms", "????", ("%.2fs" % (Time.new.to_f - @start)), "?", "??? (???)"])
    Curses.addstr("\n")
    Curses.addstr(POSITIONS2 % ["%d new calls during 1.000s period" % @new_calls.count, "?ms scheduler resolution"])
    Curses.addstr(POSITIONS2 % ["? concurrent calls (limit ?)", "Peak was ? calls, after ?s"])
    Curses.addstr(POSITIONS2 % ["? out-of-call msg (discarded)", "? open sockets"])
    Curses.addstr("\n")
    Curses.addstr((POSITIONS3 % ["", "",]) % ["Messages", "Retrans", "Timeout", "Unexpected-Msg"])
    @strings.each_with_index do |s, i|
      Curses.addstr(s % [@msg_counts[i], 0, @timeout_counts[i], @unexpected_msg_counts[i]])
    end
    Curses.refresh
  end

  def initialize
    @new_calls = MinuteLongBuffer.new
    @strings = []
    @msg_counts = []
    @unexpected_msg_counts = []
    @timeout_counts = []
    @start = Time.new.to_f

    Thread.new do
      context = ZMQ::Context.new
      socket = context.socket(ZMQ::SUB)
      socket.connect("tcp://localhost:5556")
      socket.setsockopt(ZMQ::SUBSCRIBE, "SIPP")

      socket2 = context.socket(ZMQ::REQ)
      socket2.connect("tcp://localhost:5557")
      socket2.send_string "",0
      socket2.recv_string msg2 = ""
      parse_scenario_desc msg2
      loop do
        socket.recv_strings(msgs = [])
        msgs.each do |msg|
        name, ts, scenario, callnum, callid, idx, result = msg.split(":")
        if name == "SIPP-PHASE_SUCCESS"
          inc_msg idx
        end
        if name == "SIPP-UNEXPECTED_MSG_RECVD"
          inc_unexpected idx
        end
        if name == "SIPP-RECV_TIMED_OUT"
          inc_timeout idx
        end
      end
      end
    end
  end
end

SCENARIO = Scenario.new

Curses.init_screen()

Thread.new do
  loop do
    tmp = Curses.getch
  end
end

loop do
  SCENARIO.update
  sleep 1
end

此外,当我检查 ruby​​ 版本时,它指向 2.3.3,但在运行时它显示我运行该文件的 ruby​​ 2.3.0。如果有人能解释为什么这也会帮助我。 手动在文件中安装 gems 后,我收到另一个错误,请参见下文。

/jsipp-master$ ruby curses.rb
Unable to load this gem. The libzmq library (or DLL) could not be found.
If this is a Windows platform, make sure libzmq.dll is on the PATH.
If the DLL was built with mingw, make sure the other two dependent DLLs,
libgcc_s_sjlj-1.dll and libstdc++6.dll, are also on the PATH.
For non-Windows platforms, make sure libzmq is located in this search path:
["/Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/../../ext/libzmq.dylib", "/usr/local/bin/libzmq.dylib", "/usr/bin/libzmq.dylib", "/bin/libzmq.dylib", "/usr/sbin/libzmq.dylib", "/sbin/libzmq.dylib", "/opt/X11/bin/libzmq.dylib", "/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/libzmq.dylib", "/usr/local/lib/libzmq.dylib", "/opt/local/lib/libzmq.dylib", "/usr/local/lib/libzmq.dylib", "/usr/lib64/libzmq.dylib"]
/Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/libzmq.rb:61:in `rescue in <module:LibZMQ>': The libzmq library (or DLL) could not be loaded (LoadError)
    from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/libzmq.rb:10:in `<module:LibZMQ>'
    from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core/libzmq.rb:7:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-core-1.0.6/lib/ffi-rzmq-core.rb:3:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Library/Ruby/Gems/2.3.0/gems/ffi-rzmq-2.0.6/lib/ffi-rzmq.rb:66:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
    from curses.rb:4:in `<main>'

【问题讨论】:

  • 请添加更多详细信息:粘贴 ruby​​ 文件的内容,和/或 Gemfile 的内容(如果有的话)。也请粘贴命令gem list | grep curses的结果
  • @jedi 感谢您与我们联系,我已经进一步更新了我的问题,请查看并提供一些建议,谢谢。

标签: ruby ruby-on-rails-4


【解决方案1】:

你可能没有安装curses gem。

您可以使用gem list 命令检查它是否已安装。如果您的 gem 未列出,则表示未安装:

$ gem list curses

*** LOCAL GEMS ***

$ 

如果没有安装,使用gem install命令安装gem:

$ gem install curses
Fetching: curses-1.2.4.gem (100%)
Building native extensions. This could take a while...
Successfully installed curses-1.2.4
Parsing documentation for curses-1.2.4
Installing ri documentation for curses-1.2.4
Done installing documentation for curses after 0 seconds
1 gem installed
$ 

您可以在the online gem command reference阅读更多内容。

这应该会让你超越你所看到的错误。

【讨论】:

    猜你喜欢
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    • 2012-12-27
    • 1970-01-01
    • 2017-01-11
    • 2014-06-28
    • 1970-01-01
    相关资源
    最近更新 更多