gpt4 book ai didi

ruby - Mechanize/ ruby : `require' : cannot load such file -- mechanize (LoadError)

转载 作者:太空宇宙 更新时间:2023-11-03 16:42:08 26 4
gpt4 key购买 nike

我一直在尝试使用以下方法从终端运行 ruby​​ 文件:

ruby file_cleanse_auto.rb 

但是我从 mechanize 得到一个错误:

/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mechanize (LoadError)
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from file_cleanse_auto.rb:2:in `<main>'

在我的 ruby​​ 文件中我有:

require 'open-uri'
require 'mechanize'

我能够在 Ruby shell (irb) 中毫无错误地使用 mechanize。当我尝试从命令行运行 ruby​​ 文件时,这似乎只是一个问题。我安装的ruby和mechanize版本分别是2.0.0和2.7.5。我还尝试将 Mechanize 添加到 Gemfile(有和没有 nokogiri)。这是现在的样子:

source "https://rubygems.org"
gem 'nokogiri'
gem 'mechanize'

运行后:

bundle

我得到了:

Resolving dependencies...
Using mini_portile2 2.2.0
Using unf_ext 0.0.7.4
Using mime-types-data 3.2016.0521
Using net-http-digest_auth 1.4.1
Using net-http-persistent 2.9.4
Using ntlm-http 0.1.1
Using webrobots 0.1.2
Using bundler 1.15.1
Using nokogiri 1.8.0
Using unf 0.1.4
Using mime-types 3.1
Using domain_name 0.5.20170404
Using http-cookie 1.0.3
Using mechanize 2.7.5
Bundle complete! 2 Gemfile dependencies, 14 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

但是当我尝试再次运行 ruby​​ 文件时,我仍然遇到同样的错误。有人知道我该如何解决这个错误吗?谢谢!

最佳答案

最近安装 ruby 2.4 后,我遇到了同样的问题。

你应该试试 gem install mechanize

这是因为每个 ruby installation have an independent directory for gems .希望这有效。

关于ruby - Mechanize/ ruby : `require' : cannot load such file -- mechanize (LoadError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44852292/

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