gpt4 book ai didi

Ruby 脚本找不到所需的 gem

转载 作者:数据小太阳 更新时间:2023-10-29 07:43:16 24 4
gpt4 key购买 nike

我正在尝试运行过去运行良好的 Ruby 脚本。我需要使用 Mechanize gem,所以在脚本的顶部,它说 require 'mechanize'。但是,当我现在尝试运行脚本时,终端输出显示为:

/Users/codebiker/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mechanize (LoadError)
from /Users/codebiker/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from myscript.rb:2:in `<main>'

当我按照此处的建议运行 gem env 时,我得到:

RubyGems Environment:
- RUBYGEMS VERSION: 2.2.1
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin13.0]
- INSTALLATION DIRECTORY: /Users/codebiker/.rvm/gems/ruby-2.1.0
- RUBY EXECUTABLE: /Users/codebiker/.rvm/rubies/ruby-2.1.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/codebiker/.rvm/gems/ruby-2.1.0/bin
- SPEC CACHE DIRECTORY: /Users/codebiker/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-13
- GEM PATHS:
- /Users/codebiker/.rvm/gems/ruby-2.1.0
- /Users/codebiker/.rvm/gems/ruby-2.1.0@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :benchmark => false
- :sources => ["http://rubygems.org/", "http://gemcutter.org"]
- "install" => "--no-rdoc --no-ri"
- "update" => "--no-rdoc --no-ri"
- REMOTE SOURCES:
- http://rubygems.org/
- http://gemcutter.org
- SHELL PATH:
- /Users/codebiker/.rvm/gems/ruby-2.1.0/bin
- /Users/codebiker/.rvm/gems/ruby-2.1.0@global/bin
- /Users/codebiker/.rvm/rubies/ruby-2.1.0/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/bin
- /opt/X11/bin
- /usr/texbin
- /Users/codebiker/.rvm/bin

当我运行 rvm get head 时,我得到:

Upgrading the RVM installation in /Users/codebiker/.rvm/
RVM PATH line found in /Users/codebiker/.bashrc /Users/codebiker/.zshrc.
RVM sourcing line found in /Users/codebiker/.bash_profile /Users/codebiker/.zprofile.
Upgrade of RVM in /Users/codebiker/.rvm/ is complete.

当我运行 which ruby​​ 时,我得到:

/Users/codebiker/.rvm/rubies/ruby-2.1.0/bin/ruby

ruby -v 给我:

ruby 2.1.0p0(2013-12-25 修订版 44422)[x86_64-darwin13.0]

如有任何建议、想法或提示,我们将不胜感激!我不知道这里出了什么问题。

最佳答案

必须先安装 Gem,然后才能在脚本中要求它们。安装 gem ;首先打开一个终端窗口,然后输入:

gem install GEM-NAME 或者在您的情况下:gem install mechanize

关于Ruby 脚本找不到所需的 gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21149367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com